Skip to main content
Permanently delete a task from the PhotoFlow system. This operation also cascades to delete all associated comments.

Endpoint

DELETE /api/deleteUserTask

Request Body

task_id
number
required
The ID of the task to delete.

Response

success
object
Returns the deleted task object when successful.
error
string
Returns "Something happened..." if the deletion fails (e.g., task not found).

Example Request

curl -X DELETE http://localhost:5173/api/deleteUserTask \
  -H "Content-Type: application/json" \
  -d '{
    "task_id": 42
  }'

Response Example

Success

Returns the deleted task object:
{
  "id": 42,
  "task": "Wedding photoshoot - Johnson family",
  "dueAt": "2026-03-15T10:00:00.000Z",
  "additional_information": "Outdoor ceremony at Central Park",
  "status": "pending",
  "is_finished": false,
  "taskColumn": "1",
  "amount_of_comments": 3,
  "created_at": "2026-03-01T09:00:00.000Z"
}

Error

"Something happened..."

Behavior Notes

Deletion is permanent and cannot be undone. The task and all its associated comments are removed from the database immediately.
Due to the onDelete: Cascade constraint in the database schema, all comments associated with the task are automatically deleted when the task is deleted.
After successfully deleting a task, 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 delete operation:
const tasks = await prisma.tasks.delete({
  where: { id: task_id }
});

Cascade Deletion

From the Prisma schema:
model task_comments {
  id         Int      @id @default(autoincrement())
  task       Tasks    @relation(fields: [task_id], references: [id], onDelete: Cascade)
  task_id    Int
  comment    String
  created_at DateTime @default(now())
}
The onDelete: Cascade ensures that when a task is deleted, all related comments are automatically removed.

Common Use Cases

Delete Cancelled Order

async function cancelOrder(taskId) {
  const confirmed = confirm('Are you sure you want to delete this order? This cannot be undone.');
  
  if (confirmed) {
    try {
      const deletedTask = await deleteTask(taskId);
      console.log('Order cancelled:', deletedTask.task);
    } catch (error) {
      alert('Failed to cancel order');
    }
  }
}

Bulk Delete Finished Tasks

async function cleanupFinishedTasks() {
  // First, get all tasks
  const response = await fetch('/api/getUserTasks', { method: 'POST' });
  const tasks = await response.json();
  
  // Filter finished tasks
  const finishedTasks = tasks.filter(t => t.is_finished);
  
  // Delete each one
  const results = await Promise.allSettled(
    finishedTasks.map(t => deleteTask(t.id))
  );
  
  const successCount = results.filter(r => r.status === 'fulfilled').length;
  console.log(`Deleted ${successCount} finished tasks`);
}

Error Handling

Common scenarios that trigger the error response:
  • Task ID does not exist
  • Database connection error
  • Invalid task ID format (non-numeric)
async function safeDeleteTask(taskId) {
  const response = await fetch('/api/deleteUserTask', {
    method: 'DELETE',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ task_id: taskId })
  });
  
  const result = await response.json();
  
  if (result === 'Something happened...') {
    throw new Error(`Failed to delete task ${taskId}`);
  }
  
  return result;
}

Source Reference

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

Build docs developers (and LLMs) love