Files
famapp/src/app/api/v1/events/[id]/route.ts
T

34 lines
1.3 KiB
TypeScript

import { apiJson, withApiHandler } from "@/lib/api-handler";
import { deleteEventForScope, updateEventForScope } from "@/modules/calendar/server/actions";
import { eventUpdateInput } from "@/modules/calendar/server/schemas";
import { getEventForScope } 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 event = await getEventForScope(scope, id);
return apiJson(event);
});
}
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 = eventUpdateInput.parse(body);
await updateEventForScope(scope, { id, ...parsed });
const event = await getEventForScope(scope, id);
return apiJson(event);
});
}
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 deleteEventForScope(scope, { id });
return apiJson({ ok: true });
});
}