Skip to content

[JITERA] Add PATCH /books/:id Route for Partial Updates

chi le requested to merge feat/add-patch-route-for-books-1757413186 into main

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

  1. 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 updateBook method in the bookController, allowing it to handle both PUT and PATCH requests.
  2. Shared Logic:

    • The updateBook function in controllers/bookController.js and the core logic in services/bookService.js remain unchanged. Both PUT and PATCH will utilize the same validation and update logic, ensuring consistency across the API.
  3. Validation and Schema Compliance:

    • The existing validation logic in services/bookService.js will now also apply to PATCH requests, ensuring that all updates comply with the document requirements, including the publishedYear constraint.

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.

Merge request reports