21 lines
742 B
TypeScript
21 lines
742 B
TypeScript
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);
|
|
});
|
|
}
|