[JITERA] Add PATCH /books/:id Route for Partial Updates
Created by: chi-jitera
Overview
This pull request introduces a new endpoint for updating book records using the PATCH method. The new route allows for partial updates to book records, adhering to the existing validation and update logic already implemented for the PUT method.
Changes Made
-
Added PATCH Route:
- In
routes/bookRoutes.js, a new route has been added:router.patch('/books/:id', bookController.updateBook); - This route points to the existing
updateBookmethod in thebookController, allowing it to handle both PUT and PATCH requests.
- In
-
Shared Logic:
- The
updateBookfunction incontrollers/bookController.jsand the core logic inservices/bookService.jsremain unchanged. Both PUT and PATCH will utilize the same validation and update logic, ensuring consistency across the API.
- The
-
Validation and Schema Compliance:
- The existing validation logic in
services/bookService.jswill now also apply to PATCH requests, ensuring that all updates comply with the document requirements, including the publishedYear constraint.
- The existing validation logic in
Result
- The PATCH /books/:id endpoint is now available for use, allowing clients to perform partial updates on book records while maintaining the integrity of the data and adhering to the API documentation.
- Consider updating the API documentation to include the new PATCH method for completeness.