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.

Fetching the product data (CRUD)

Fetching the product data (CRUD)

Now, let's see how to fetch that is get the product data. Inside the product service file, I'll create a new method called get all and return this dot product repository dot find method. The find method returns all the records from the table. Now, in the controllers file, I'll create a getRoute handler with path getAll, and a method which returns this.productService.getAll. This will retrieve and display all the records from the table. Let's save this and go to the postman. I'll create a new tab and we'll set the path. And we get all the records from the table. Currently the records are getting displayed based on their ID. But let's say we want to display them based on the product price. Then we can update the query by setting the order property inside the find method and set the field that is price to ascending order. Now let's check the output once again. I'll make the request and now the records are getting displayed based on the product's price that is in ascending order of price.…

Contents