Add /api/health and /api/tasks route handlers

This commit is contained in:
Grok Bot
2026-11-26 09:10:37 +00:00
parent 8be52a3647
commit a85f6d95d8
3 changed files with 59 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
import { NextResponse } from 'next/server';
import { deleteTask, isStatus, moveTask } from '@/lib/tasks';
export const dynamic = 'force-dynamic';
type Ctx = { params: Promise<{ id: string }> };
export async function PATCH(req: Request, { params }: Ctx) {
const id = Number((await params).id);
const body = await req.json().catch(() => null);
if (!Number.isInteger(id) || !isStatus(body?.status)) {
return NextResponse.json({ error: 'valid id and status (todo|doing|done) required' }, { status: 400 });
}
const task = await moveTask(id, body.status);
return task ? NextResponse.json(task) : NextResponse.json({ error: 'not found' }, { status: 404 });
}
export async function DELETE(_req: Request, { params }: Ctx) {
const id = Number((await params).id);
if (!Number.isInteger(id)) return NextResponse.json({ error: 'invalid id' }, { status: 400 });
return (await deleteTask(id)) ? new NextResponse(null, { status: 204 }) : NextResponse.json({ error: 'not found' }, { status: 404 });
}