feat: api v1 routes for calendar lists and notes
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user