feat: api v1 routes for calendar lists and notes

This commit is contained in:
ginnoir
2026-07-04 19:03:08 -05:00
parent ea5d1d050c
commit d4304b005c
25 changed files with 1141 additions and 236 deletions
+37
View File
@@ -0,0 +1,37 @@
import { apiError, apiJson, withApiHandler } from "@/lib/api-handler";
import { createEventForScope } from "@/modules/calendar/server/actions";
import { eventInput } from "@/modules/calendar/server/schemas";
import { listEventsForScope } from "@/modules/calendar/server/queries";
function parseCalendarIds(value: string | null): "all" | string[] {
if (!value || value === "all") return "all";
return value
.split(",")
.map((id) => id.trim())
.filter(Boolean);
}
export async function GET(request: Request) {
return withApiHandler(request, async (scope, req) => {
const url = new URL(req.url);
const from = url.searchParams.get("from");
const to = url.searchParams.get("to");
const calendarIds = parseCalendarIds(url.searchParams.get("calendarIds"));
if (!from || !to) {
return apiError("from and to query parameters are required", 400);
}
const events = await listEventsForScope(scope, { from, to, calendarIds });
return apiJson(events);
});
}
export async function POST(request: Request) {
return withApiHandler(request, async (scope, req) => {
const body: unknown = await req.json();
const parsed = eventInput.parse(body);
const event = await createEventForScope(scope, parsed);
return apiJson(event, 201);
});
}