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 { 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 });
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user