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.

Inserting product data (CRUD)

Inserting product data (CRUD)

Alright, so as we are now connected to the database table, let's start implementing the CRUD functionalities. In this lecture, we will see how to insert product data inside the table. So first, we need a products controller file. I'll give the command nest generate controller products slash controller slash product hyphen hyphen no hyphen spec. Similarly, we will need a separate module file for the products and a service file. And the files are created inside the dedicated folders. Now one more thing we need in a product DTO file to have an extra type checking rather than simply adding the data directly to the fields. I'll create a folder DTO and a file product.dto.ts. Here I'll create a class named product DTO, which will have the same properties defined inside the product entity. Apart from id and date, we only need two values that is product name of type string and price of type number. If we want, we can also add a few class validators like here I'll give isStringValidator to…

Contents