Skip to main content
Mark a task as completed by setting its is_finished status to true.

Endpoint

POST /api/finishUserTask

Request Body

id
number
required
The ID of the task to mark as finished.

Response

success
string
Returns "Worked!" when the task is successfully marked as finished.
error
string
Returns "Invalid!" if the operation fails (e.g., task not found).

Example Request

curl -X POST http://localhost:5173/api/finishUserTask \
  -H "Content-Type: application/json" \
  -d '{
    "id": 42
  }'

Response Example

"Worked!"

Error Response

"Invalid!"

Behavior Notes

This endpoint only sets is_finished to true. It does not modify other task fields like status, dueAt, or taskColumn.
After successfully finishing a task, emit a database-change event via Socket.io to notify other clients. See Real-time Updates for details.
There is no endpoint to “unfinish” a task. If you need to reverse this operation, use the Update Task endpoint with taskID to set is_finished back to false.

Database Update

The endpoint performs the following Prisma update:
await prisma.tasks.update({
  where: { id: id },
  data: {
    id: id,
    is_finished: true
  }
});

Common Use Cases

Complete a Task After Delivery

// After uploading final photos and confirming with client
async function completeOrder(taskId) {
  await finishTask(taskId);
  console.log(`Task ${taskId} completed successfully!`);
}

Bulk Complete Multiple Tasks

async function finishMultipleTasks(taskIds) {
  const results = await Promise.all(
    taskIds.map(id => finishTask(id))
  );
  
  const successCount = results.filter(r => r === 'Worked!').length;
  console.log(`${successCount} of ${taskIds.length} tasks completed`);
}

finishMultipleTasks([1, 5, 12, 23]);
  • Get Tasks - Retrieve all tasks (including is_finished status)
  • Create Task - Update task fields (alternative to set is_finished)
  • Delete Task - Permanently remove a task

Source Reference

Implementation: src/routes/api/(tasks-clients)/finishUserTask/+server.ts:5

Build docs developers (and LLMs) love