User entity
We shall now create the User entity, defining its class and attributes.
Now that we have our project configured, we can start marching towards our main objective - developing our shop backend system. Let's create the User
resource. We shall do so inside the domain folder, to group domain's entities together.
Choose the following options
Transport Layer - REST API
CRUD entry points - Yes
The nest resource includes
The entity class
DTOs for creating and updating an entity
A module to encapsulate this context
A controller with the basic routes for this entity
A service with the logic for the routes
Automated tests
But right now, we should focus on the entity class. So let's go to src -> domain -> users -> entities -> user.entity.
When the file extension is not shown, you can consider that it is a TypeScript (.ts) file.
Inside the class, we will insert the entity's attributes.
After that, we should copy all these fields (except id) and paste them in the create-user.dto file located in the dto folder inside users. This process will be necessary for the next lesson.
Prefixing DTO fields with
readonly
is a good practice.
The ALT + CLICK shortcut allows for multiple cursors, and thus prefixing all the fields at once.
Commit - Creating the first entity
Last updated