Journal dashboard widgets and quick-add; rich-text quick-add dialogs. Dashboard draft sync for live edit previews; assistant bubble + API tools. Journal UX: stress slider, mood grid, query cap fix.
24 lines
1013 B
TypeScript
24 lines
1013 B
TypeScript
import { apiJson, withApiHandler } from "@/lib/api-handler";
|
|
import { createJournalEntryForScope } from "@/modules/journal/server/actions";
|
|
import { journalEntryInput } from "@/modules/journal/server/schemas";
|
|
import { listJournalEntriesForScope } from "@/modules/journal/server/queries";
|
|
|
|
export async function GET(request: Request) {
|
|
return withApiHandler(request, async (scope, req) => {
|
|
const url = new URL(req.url);
|
|
const limitParam = url.searchParams.get("limit");
|
|
const limit = limitParam ? Math.min(Math.max(Number(limitParam) || 20, 1), 100) : undefined;
|
|
const entries = await listJournalEntriesForScope(scope, limit ? { limit } : undefined);
|
|
return apiJson(entries);
|
|
});
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
return withApiHandler(request, async (scope, req) => {
|
|
const body: unknown = await req.json();
|
|
const parsed = journalEntryInput.parse(body);
|
|
const entry = await createJournalEntryForScope(scope, parsed);
|
|
return apiJson(entry, 201);
|
|
});
|
|
}
|