[JITERA] Add PATCH /books/:id route to enable partial updates
Created by: chi-jitera
Overview
This pull request introduces a new PATCH route for updating book records partially by their ID. The logic for handling the PATCH request is already implemented in the service and controller, and this update integrates the route into the application.
Changes
-
Updated
/routes/bookRoutes.js:- Added the PATCH route for
/books/:idwhich maps to thebookController.patchBookmethod. This allows clients to perform partial updates on book records.
- Added the PATCH route for
Code Changes
const express = require('express');
const bookController = require('../controllers/bookController');
const router = express.Router();
router.post('/books', bookController.createBook);
router.get('/books', bookController.getAllBooks);
router.get('/books/search', bookController.searchBooks);
router.get('/books/:id', bookController.getBookById);
router.put('/books/:id', bookController.updateBook);
router.patch('/books/:id', bookController.patchBook); // <-- Added PATCH
router.delete('/books/:id', bookController.deleteBook);
module.exports = router;
This addition enables clients to send PATCH requests to update specific fields of a book without needing to send the entire book object.