nestjs-boilerplate icon indicating copy to clipboard operation
nestjs-boilerplate copied to clipboard

Best practice for adding user_extra extension entity and related CLI commands

Open zieglar opened this issue 5 months ago • 4 comments

Background: I would like to extend the user entity by adding an extra property class, such as user_extra. What would be the best practice to achieve this in this project? For example, should I create a separate entity and link it with a relation, or is there a preferred approach in your codebase?

Additional question: Are there any CLI commands or scripts already set up in this repository to help generate new entities? If so, could you please share some guidance or examples?

Thank you!

zieglar avatar Jun 15 '25 12:06 zieglar

@zieglar

I would like to extend the user entity by adding an extra property class, such as user_extra. What would be the best practice to achieve this in this project? For example, should I create a separate entity and link it with a relation, or is there a preferred approach in your codebase?

It's up to you and based on your project's requirements. You can add properties directly to the User entity, or you can create an additional entity via the CLI and attach it to the User entity.

Additional question: Are there any CLI commands or scripts already set up in this repository to help generate new entities? If so, could you please share some guidance or examples?

You can find the video here https://github.com/brocoders/nestjs-boilerplate?tab=readme-ov-file#description-

Shchepotin avatar Jun 17 '25 23:06 Shchepotin

@Shchepotin I mean, if I need to add a subsidiary entity class to the user's infrastructure, how to operate it is the best practice, or do you suggest adding a new entity module?

zieglar avatar Jun 18 '25 01:06 zieglar

@zieglar excuse me for my unclear answer, but not sure that there is a best practice for this. In your case, you can create a new module "UserExtra" and add a relation to User.

Shchepotin avatar Jun 18 '25 21:06 Shchepotin

@Shchepotin It is not recommended to put User-related models under users/infrastructure/persistence/relational, right?

zieglar avatar Jun 19 '25 02:06 zieglar

@zieglar, usually we put a new module in the /src even if it is related to another module.

Shchepotin avatar Jun 19 '25 22:06 Shchepotin

Alright, thank you for the reply.

zieglar avatar Jun 20 '25 01:06 zieglar