Skip to main content
Update the text content of an existing comment on a task.

Endpoint

POST /api/updateCommentFromTask

Request Body

comment_id
number
required
The ID of the comment to update.
new_comment
string
required
The new text content for the comment.

Response

success
string
Returns "Worked!" when the comment is updated successfully.
error
string
Returns "Invalid!" if the operation fails (e.g., comment not found).

Example Request

curl -X POST http://localhost:5173/api/updateCommentFromTask \
  -H "Content-Type: application/json" \
  -d '{
    "comment_id": 15,
    "new_comment": "Client requested to move the shoot to 3pm (updated)"
  }'

Response Example

"Worked!"

Error Response

"Invalid!"

Behavior Notes

Updating a comment does not change its created_at timestamp. There is no updated_at field in the comment schema.
This operation does not affect the task’s amount_of_comments counter.
After successfully updating a comment, emit a database-change event via Socket.io to notify other clients. See Real-time Updates for details.

Database Operation

The endpoint performs the following Prisma update:
await prisma.task_comments.update({
  where: { id: comment_id },
  data: {
    id: comment_id,
    comment: new_comment
  }
});

Common Use Cases

Fix Typo in Comment

async function fixCommentTypo(commentId, correctedText) {
  await updateComment(commentId, correctedText);
  console.log('Comment corrected');
}

fixCommentTypo(15, 'Meeting scheduled for 3pm (not 2pm)');

Add Timestamp to Existing Comment

async function addTimestampToComment(commentId, originalText) {
  const timestamp = new Date().toLocaleString();
  const updatedText = `[Edited ${timestamp}] ${originalText}`;
  await updateComment(commentId, updatedText);
}

addTimestampToComment(15, 'Client confirmed attendance');

Redact Sensitive Information

async function redactComment(commentId, reason = 'redacted') {
  const redactedText = `[This comment has been ${reason}]`;
  await updateComment(commentId, redactedText);
}

redactComment(15, 'removed at client request');

Getting Comment ID

To update a comment, you need its ID. Since there’s no dedicated endpoint to fetch comments, you’ll need to query them directly:
// Example: Get all comments for a task
const comments = await prisma.task_comments.findMany({
  where: { task_id: taskId },
  orderBy: { created_at: 'desc' }
});

// Then update a specific comment
const commentToUpdate = comments[0];
await updateComment(commentToUpdate.id, 'New text');

Edit History

The current schema does not track edit history. When you update a comment, the original text is permanently replaced with no record of the previous content.
If you need edit history, consider:
  • Appending “(edited)” to the comment text
  • Including edit timestamps in the comment text
  • Extending the schema to add updated_at and edit_history fields

Source Reference

Implementation: src/routes/api/(comments)/updateCommentFromTask/+server.ts:5

Build docs developers (and LLMs) love