tasks: add individual completion deletion API and UI

This commit is contained in:
2026-04-02 07:47:57 +02:00
parent 62a22ca668
commit 3daea9a057
2 changed files with 57 additions and 0 deletions
@@ -0,0 +1,22 @@
import type { RequestHandler } from '@sveltejs/kit';
import { TaskCompletion } from '$models/TaskCompletion';
import { dbConnect } from '$utils/db';
import { error, json } from '@sveltejs/kit';
export const DELETE: RequestHandler = async ({ params, locals }) => {
const auth = await locals.auth();
if (!auth?.user?.nickname) throw error(401, 'Not logged in');
await dbConnect();
const completion = await TaskCompletion.findById(params.id);
if (!completion) throw error(404, 'Completion not found');
if (completion.completedBy !== auth.user.nickname) {
throw error(403, 'You can only delete your own completions');
}
await completion.deleteOne();
return json({ success: true });
};