amount_of_comments counter.
Endpoint
Request Body
The ID of the comment to delete.
The ID of the task that the comment belongs to. Required to update the comment counter.
Response
Returns the deleted comment object when successful.
Returns
"Invalid!" if the deletion fails (e.g., comment not found).Example Request
Response Example
Success
Returns the deleted comment object:Error
Behavior Notes
Deleting a comment decrements the task’s
amount_of_comments field by 1.After successfully deleting a comment, emit a
database-change event via Socket.io to notify other clients. See Real-time Updates for details.Database Operations
The endpoint performs two Prisma operations:- Delete the comment:
- Decrement the comment counter:
Common Use Cases
Remove Outdated Comment
Delete All Comments for a Task
Safe Delete with Validation
Error Handling
Common scenarios that trigger the error response:- Comment ID does not exist
- Task ID does not exist
- Database connection error
- Invalid ID format (non-numeric)
Cascade Deletion
If you delete a task using Delete Task, all associated comments are automatically deleted due to the
onDelete: Cascade constraint in the schema. You don’t need to manually delete comments first.Why Both IDs Are Required
The endpoint requires bothcomment_id and task_id because:
comment_idis used to identify and delete the commenttask_idis used to decrement the task’s comment counter
comment_id, you can query the comment first to get the task_id:
Related Endpoints
- Add Comment - Create a new comment
- Update Comment - Modify a comment
- Delete Task - Delete task and all comments
Source Reference
Implementation:src/routes/api/(comments)/deleteCommentFromTask/+server.ts:5