feat: implement PATCH /comments/:id route to partially update a comment by ID
Summary
This pull request implements the PATCH /comments/:id route that allows authenticated users to partially update a specific comment by its ID. The route ensures that only the author of the comment or an admin can perform the update.
Changes Implemented
Added patchCommentById method to commentController to handle partial updates to comments.
Created a new route in commentRoutes.js for PATCH /comments/:id, protected by authenticateToken.
Added verification to ensure only the author of the comment or an admin can update the comment.
Implemented error handling to return 404 Not Found if the comment is not found.
Verified functionality with Postman tests.
How to Test
Partial Update as Author:
Send a PATCH request to http://localhost:5000/comments/:id with a valid comment ID where the author matches the authenticated user.
Ensure the comment is partially updated successfully.
Partial Update as Admin:
Send a PATCH request to http://localhost:5000/comments/:id with a valid comment ID using an admin token.
Ensure the comment is partially updated successfully.
Unauthorized Update Attempt:
Send a PATCH request to http://localhost:5000/comments/:id with a valid comment ID using a token from a different user (not the author and not an admin).
Ensure the response is 403 Forbidden.
Comment Not Found:
Send a PATCH request to http://localhost:5000/comments/:id with a non-existent comment ID.
feat: implement PATCH /comments/:id route to partially update a comment by ID
Summary
This pull request implements the
PATCH /comments/:id
route that allows authenticated users to partially update a specific comment by its ID. The route ensures that only the author of the comment or an admin can perform the update.Changes Implemented
patchCommentById
method tocommentController
to handle partial updates to comments.commentRoutes.js
forPATCH /comments/:id
, protected byauthenticateToken
.404 Not Found
if the comment is not found.How to Test
Partial Update as Author:
PATCH
request tohttp://localhost:5000/comments/:id
with a valid comment ID where the author matches the authenticated user.Partial Update as Admin:
PATCH
request tohttp://localhost:5000/comments/:id
with a valid comment ID using an admin token.Unauthorized Update Attempt:
PATCH
request tohttp://localhost:5000/comments/:id
with a valid comment ID using a token from a different user (not the author and not an admin).403 Forbidden
.Comment Not Found:
PATCH
request tohttp://localhost:5000/comments/:id
with a non-existent comment ID.404 Not Found
.Example Request (Admin)
Example Response
Resolves #151