import { getTask, updateTask } from '@/lib/delegation.js';

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

export async function GET(_req, { params }) {
  const { id } = await params;
  const task = getTask(id);
  return task
    ? Response.json({ task })
    : new Response('Task not found', { status: 404 });
}

export async function PATCH(req, { params }) {
  const { id } = await params;
  const body = await req.json().catch(() => ({}));
  return Response.json({ task: updateTask(id, body) });
}
