The User & Todo Models
First of all, if you have downloaded the source code of the previous tutorial, compile and run the existing migrations.
#
The User ModelThen open the user.entity.ts
file from the src/app/entities
directory. The User
entity is the main class used by the framework's authentication system.
Add the email
and password
properties and the setPassword
method.
The setPassword
method uses hashPassword
to hash passwords before storing them in the database. You must use this method to set a password instead of directly assigning a value to the password
attribute.
#
The Todo ModelThe Todo model defined in the previous tutorial now needs a owner
property to know which user it belongs to.
Replace the content of todo.entity.ts
.
In the database the todo
table will look like this:
#
The MigrationsThe last step is to create/update the tables in the database. As in the first tutorial, you will use migrations for this.
Generate the migrations from the entities.
A new file is added in src/migrations
.
Then run the new migration file.