Ship journal entries with mood tracking, insights, and Recharts charts. Adds v1 API endpoints per ADR 0005 and migration 0020_journal_entries.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { apiJson, withApiHandler } from "@/lib/api-handler";
|
|
import {
|
|
deleteJournalEntryForScope,
|
|
updateJournalEntryForScope,
|
|
} from "@/modules/journal/server/actions";
|
|
import { updateJournalEntryInput } from "@/modules/journal/server/schemas";
|
|
import { getJournalEntryForScope } from "@/modules/journal/server/queries";
|
|
|
|
export async function GET(request: Request, context: { params: Promise<{ id: string }> }) {
|
|
const { id } = await context.params;
|
|
return withApiHandler(request, async (scope) => {
|
|
const entry = await getJournalEntryForScope(scope, id);
|
|
return apiJson(entry);
|
|
});
|
|
}
|
|
|
|
export async function PATCH(request: Request, context: { params: Promise<{ id: string }> }) {
|
|
const { id } = await context.params;
|
|
return withApiHandler(request, async (scope, req) => {
|
|
const body: unknown = await req.json();
|
|
const parsed = updateJournalEntryInput.parse({ ...(body as object), id });
|
|
const entry = await updateJournalEntryForScope(scope, parsed);
|
|
return apiJson(entry);
|
|
});
|
|
}
|
|
|
|
export async function DELETE(request: Request, context: { params: Promise<{ id: string }> }) {
|
|
const { id } = await context.params;
|
|
return withApiHandler(request, async (scope) => {
|
|
await deleteJournalEntryForScope(scope, { id });
|
|
return apiJson({ ok: true });
|
|
});
|
|
}
|