[JITERA] Add PATCH /books/:id endpoint for partial updates
Created by: chi-jitera
Overview
This pull request introduces a new endpoint to allow partial updates of book records via a PATCH request. The new functionality is implemented in the bookRoutes.js and bookController.js files, along with necessary changes in the bookService.js to handle the update logic.
Changes
-
Updated
bookRoutes.js:- Added a new route for the PATCH method to handle requests to
/books/:id. - This route maps to the
patchBookmethod in thebookController.
// routes/bookRoutes.js router.patch('/books/:id', bookController.patchBook); - Added a new route for the PATCH method to handle requests to
-
Implemented
patchBookmethod inbookController.js:- Created the
patchBookmethod to handle the logic for updating book records. - The method validates the input and updates only the fields provided in the request body.
// controllers/bookController.js async patchBook(req, res) { const { id } = req.params; const updates = req.body; // Validate and update logic here } - Created the
-
Updated
bookService.js:- Implemented the
patchBookmethod to perform the actual update in the database. - Ensured that only the fields present in the request body are updated.
// services/bookService.js async patchBook(id, updates) { // Logic to update the book in the database } - Implemented the
This new functionality will enhance the API by allowing clients to update only specific fields of a book without needing to send the entire book object.