[JITERA] Add PATCH /books/:id endpoint for partial updates
Created by: chi-jitera
Overview
This pull request introduces a new PATCH endpoint for updating book records in the application. The addition of the PATCH /books/:id route allows for partial updates to book resources, adhering to RESTful best practices.
Changes
-
Route Definition:
- Added a new route in
/routes/bookRoutes.jsfor handling PATCH requests.
router.patch('/books/:id', bookController.updateBook); // PATCH for partial updates - Added a new route in
-
Controller Logic:
- The existing
updateBookfunction in/controllers/bookController.jsis utilized for both PUT and PATCH requests. This function is capable of handling partial updates due to Mongoose'sfindByIdAndUpdatemethod, which supports updating only the fields provided in the request body.
- The existing
-
Service Logic:
- The service function
updateBookin/services/bookService.jsremains unchanged, as it already accommodates partial updates through Mongoose's capabilities.
- The service function
-
Model Definition:
- The Mongoose schema in
/models/Book.jsis unaffected by this change, as the PATCH functionality leverages the existing model structure.
- The Mongoose schema in
This implementation ensures that clients can now perform partial updates on book records, enhancing the flexibility and usability of the API.