feat: api v1 routes for calendar lists and notes
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user