-
Notifications
You must be signed in to change notification settings - Fork 46
Entity generation
The boilerplate provides rsgen, a small cli tool which can be work as entity generator. The tool is installed by default in your node runtime.
Obviously to gain a little bit of time with repetitive and boring tasks. 🕐 😎
So, you can generate:
- Controller
- Routes
- Repository
- Model
- Validations
- Subscriber
- Query string interface
- Request interface
- Business service and data-layer service (resource only)
- E2e tests
- Fixtures
Open your terminal and go to the root of your project:
$ cd path-to/the-root/of-your-project/
Run rsgen command:
$ rsgen
Prompt ask first what you want to generate: a core component (in this cas don't hesitate to send a PR 🙏) or a resource as module.
According to this choice, the files will be generated into the core or the resources directory. If you wish generate a business module, keep the default choice and generate a resource.
Next, enter the name of the entity to generate. You can provide one or many words separated by spaces, generator will use hyphens for filename, and PascalCase for entity name.
Finaly, indicates who can access to the generated resource by choosing roles in the list.
And Voilà ! 🎺 🎺 🎺
Your module has been generated, according to the previous example you can find the following files:
-
/src/api/resources/car/
- /src/api/resources/car/car.route.ts
- /src/api/resources/car/car.controler.ts
- /src/api/resources/car/car.model.ts
- /src/api/resources/car/car.repository.ts
- /src/api/resources/car/car.validation.ts
- /test/e2e/0[xxx]-car.e2e.test.js
- /test/utils/fixtures/car.js
Generated files contains only basic features and some parts must be filled by yourself :
- Model is filled with a primary auto-incremented id, and date system columns. Fill it with your columns and relations.
- Validation rules are created but empty by default. Fill it with your rules.
- Tests e2e will be improved with your use cases.
- Fixture should be filled according to your model.