34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { apiJson, withApiHandler } from "@/lib/api-handler";
|
|
import { deleteCalendarForScope, updateCalendarForScope } from "@/modules/calendar/server/actions";
|
|
import { calendarUpdateInput } from "@/modules/calendar/server/schemas";
|
|
import { getCalendarForScope } from "@/modules/calendar/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 calendar = await getCalendarForScope(scope, id);
|
|
return apiJson(calendar);
|
|
});
|
|
}
|
|
|
|
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 = calendarUpdateInput.parse(body);
|
|
await updateCalendarForScope(scope, { id, ...parsed });
|
|
const calendar = await getCalendarForScope(scope, id);
|
|
return apiJson(calendar);
|
|
});
|
|
}
|
|
|
|
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 deleteCalendarForScope(scope, { id });
|
|
return apiJson({ ok: true });
|
|
});
|
|
}
|