From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Injecting the user schema

Injecting the user schema

Now, let's update the user service file by injecting the user schema and defining proper methods for database interactions. So inside the user service file, I'll first inject the user model, I'll give the inject model decorator, user dot name, and create a private read only property that is user model of type model, passing the generic type of model as user schema. Now let's update the create user method, I'll remove the user repository, and instead give the user model will also remove the create method, because the user model is a constructor. So we will have to instantiate it using the new keyword. Here as well, instead of the user repository, I'll give the new user variable to which the save method is assigned. That's it. Let's save this. Let's update the find user by username method now. All I have to do is give the user model instead of the user repository and dot execute method. That's it. The compare passwords method is going to remain as it is. And by this we have successfully…

Contents