feat: implement DELETE /comments/event/:eventId route to delete all comments by event ID
Summary
This pull request implements the DELETE /comments/event/:eventId route that allows the creator of an event to delete all comments by a specific event ID. The route ensures that only the creator of the event can perform the deletion.
Changes Implemented
Added deleteCommentsByEventId method to commentController to handle deleting all comments by event ID.
Created a new route in commentRoutes.js for DELETE /comments/event/:eventId, protected by authenticateToken.
Implemented error handling to return 404 Not Found if no comments are found for the event.
Verified functionality with Postman tests.
Added a check to ensure only the creator of the event can delete the comments.
How to Test
Delete All Comments as Event Creator:
Send a DELETE request to http://localhost:5000/comments/event/:eventId with a valid event ID and a token belonging to the creator of the event in the Authorization header.
Ensure the response includes { message: 'All comments deleted successfully' }.
No Comments Found:
Send a DELETE request to http://localhost:5000/comments/event/:eventId with a valid event ID but no comments for that event.
Ensure the response is 404 Not Found.
Unauthorized Deletion Attempt:
Send a DELETE request to http://localhost:5000/comments/event/:eventId with a valid event ID and a token from a user who is not the creator of the event.
feat: implement DELETE /comments/event/:eventId route to delete all comments by event ID
Summary
This pull request implements the
DELETE /comments/event/:eventId
route that allows the creator of an event to delete all comments by a specific event ID. The route ensures that only the creator of the event can perform the deletion.Changes Implemented
deleteCommentsByEventId
method tocommentController
to handle deleting all comments by event ID.commentRoutes.js
forDELETE /comments/event/:eventId
, protected byauthenticateToken
.404 Not Found
if no comments are found for the event.How to Test
Delete All Comments as Event Creator:
DELETE
request tohttp://localhost:5000/comments/event/:eventId
with a valid event ID and a token belonging to the creator of the event in theAuthorization
header.{ message: 'All comments deleted successfully' }
.No Comments Found:
DELETE
request tohttp://localhost:5000/comments/event/:eventId
with a valid event ID but no comments for that event.404 Not Found
.Unauthorized Deletion Attempt:
DELETE
request tohttp://localhost:5000/comments/event/:eventId
with a valid event ID and a token from a user who is not the creator of the event.403 Forbidden
.Example Request (Event Creator)
Example Response
New Issues Created
Resolves