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.

Controller fundamentals (@Patch handler)

Controller fundamentals (@Patch handler)

Now, let's see how the patch request is carried out. So inside the controller file, I'll give patch handler and the method partial update. Let's define the functionality in the service file. Below the update method, I'll create a method partial update. And in the argument, I'll give id of type string, and we'll create a product data object with title, description, and price as properties. We are following the same logic like we did for the put request. And then in the method, we destructure the product object and the index value from the find product method with ID as parameter. Then we create a new object, updated product, and we merge the existing product object with the product data passed in the parameter. So any properties existing in the product data will override the corresponding properties in the product object, effectively updating the product with the new data. Then we assign the updated product object to the product array by giving this dot product index is equal to…

Contents