30 lines
987 B
TypeScript
30 lines
987 B
TypeScript
import { apiJson, withApiHandler } from "@/lib/api-handler";
|
|
import { createCalendarForScope } from "@/modules/calendar/server/actions";
|
|
import { calendarInput } from "@/modules/calendar/server/schemas";
|
|
import { listCalendarsForScope } from "@/modules/calendar/server/queries";
|
|
|
|
export async function GET(request: Request) {
|
|
return withApiHandler(request, async (scope) => {
|
|
const calendars = await listCalendarsForScope(scope);
|
|
return apiJson(calendars);
|
|
});
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
return withApiHandler(request, async (scope, req) => {
|
|
const body: unknown = await req.json();
|
|
const parsed = calendarInput.parse(body);
|
|
const calendar = await createCalendarForScope(scope, parsed);
|
|
return apiJson(
|
|
{
|
|
id: calendar.id,
|
|
name: calendar.name,
|
|
color: calendar.color,
|
|
visibility: calendar.visibility as "private" | "household",
|
|
ownerId: calendar.ownerId,
|
|
},
|
|
201,
|
|
);
|
|
});
|
|
}
|