Files
famapp/src/app/api/v1/lists/route.ts
T

34 lines
1.1 KiB
TypeScript

import { apiJson, withApiHandler } from "@/lib/api-handler";
import { createListForScope } from "@/modules/lists/server/actions";
import { listInput } from "@/modules/lists/server/schemas";
import { listListsForScope } from "@/modules/lists/server/queries";
export async function GET(request: Request) {
return withApiHandler(request, async (scope, req) => {
const url = new URL(req.url);
const type = url.searchParams.get("type") ?? undefined;
const lists = await listListsForScope(scope.householdId, type ? { type } : undefined);
return apiJson(lists);
});
}
export async function POST(request: Request) {
return withApiHandler(request, async (scope, req) => {
const body: unknown = await req.json();
const parsed = listInput.parse(body);
const list = await createListForScope(scope, parsed);
return apiJson(
{
id: list.id,
type: list.type,
name: list.name,
archived: list.archived,
openCount: 0,
doneCount: 0,
createdAt: list.createdAt.toISOString(),
},
201,
);
});
}