import { apiJson, withApiHandler } from "@/lib/api-handler"; import { deleteListForScope, updateListForScope } from "@/modules/lists/server/actions"; import { listUpdateInput } from "@/modules/lists/server/schemas"; import { getListForScope } from "@/modules/lists/server/queries"; import { z } from "zod"; export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) { const { id } = await params; return withApiHandler(request, async (scope) => { const list = await getListForScope(scope.householdId, id); return apiJson(list); }); } export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) { const { id } = await params; return withApiHandler(request, async (scope, req) => { const body: unknown = await req.json(); const parsed = listUpdateInput.parse(body); await updateListForScope(scope, { id, ...parsed }); const list = await getListForScope(scope.householdId, id); return apiJson(list); }); } export async function DELETE(request: Request, { params }: { params: Promise<{ id: string }> }) { const { id } = await params; return withApiHandler(request, async (scope) => { z.string().uuid().parse(id); await deleteListForScope(scope, { id }); return apiJson({ ok: true }); }); }