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 product schema

Injecting the product schema

Now, let's update the product service file by injecting the product schema and defining proper methods for database interactions. So inside the product service file, I'll first inject the product model. I'll give the inject model decorator product dot name and create a private read only property that is product model of type model. the generic type of model as product schema. Now let's update the methods. First is the add product method. I'll give the product model instead of the product repository, remove the create method and passing the new keyword. And we'll update the save method. Next is the get all method. I'll give the product model and the execute method. Then for the get one method, I'll set the ID type to string, because the MongoDB generates a string ID of each document. Then I'll give the product model dot find by ID method. And I'll remove the where property and state only the ID and the execute method. Next is the update product method, where I'll set the ID of type…

Contents