amount_of_comments counter.
Endpoint
Request Body
The ID of the task to add the comment to.
The text content of the comment.
Response
Returns
"Successful!" when the comment is added successfully.Returns
"Invalid!" if the operation fails (e.g., task not found).Example Request
Response Example
Error Response
Behavior Notes
The
created_at timestamp is automatically set to the current date and time when the comment is created.Adding a comment increments the task’s
amount_of_comments field by 1. This counter is useful for displaying comment counts without querying all comments.After successfully adding 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:- Create the comment:
- Increment the comment counter:
Comment Schema
Comments are stored with the following structure:Common Use Cases
Add Status Update
Add Client Feedback
Add Multiple Comments
Comment Display
To retrieve and display comments, you’ll need to query the database directly or extend the API. Comments are related to tasks via thetask_id foreign key:
Related Endpoints
- Update Comment - Modify an existing comment
- Delete Comment - Remove a comment
- Get Tasks - Retrieve tasks with
amount_of_comments
Source Reference
Implementation:src/routes/api/(comments)/addCommentToTask/+server.ts:4