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
+32
View File
@@ -0,0 +1,32 @@
import { apiJson, withApiHandler } from "@/lib/api-handler";
import { deleteNoteForScope, updateNoteForScope } from "@/modules/notes/server/actions";
import { updateNoteInput } from "@/modules/notes/server/schemas";
import { getNoteForScope } from "@/modules/notes/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 note = await getNoteForScope(scope.householdId, id);
return apiJson(note);
});
}
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 = updateNoteInput.omit({ id: true }).parse(body);
const note = await updateNoteForScope(scope, { id, ...parsed });
return apiJson(note);
});
}
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 deleteNoteForScope(scope, { id });
return apiJson({ ok: true });
});
}
+20
View File
@@ -0,0 +1,20 @@
import { apiJson, withApiHandler } from "@/lib/api-handler";
import { createNoteForScope } from "@/modules/notes/server/actions";
import { noteInput } from "@/modules/notes/server/schemas";
import { listNotesForScope } from "@/modules/notes/server/queries";
export async function GET(request: Request) {
return withApiHandler(request, async (scope) => {
const notes = await listNotesForScope(scope.householdId);
return apiJson(notes);
});
}
export async function POST(request: Request) {
return withApiHandler(request, async (scope, req) => {
const body: unknown = await req.json();
const parsed = noteInput.parse(body);
const note = await createNoteForScope(scope, parsed);
return apiJson(note, 201);
});
}