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.
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { z } from "zod";
|
|
import { apiJson, withApiHandler } from "@/lib/api-handler";
|
|
import { logCareForScope } from "@/modules/garden/server/actions";
|
|
import { careLogInput } from "@/modules/garden/server/schemas";
|
|
import { getCareLogsForScope } from "@/modules/garden/server/queries";
|
|
|
|
export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params;
|
|
return withApiHandler(request, async (scope, req) => {
|
|
z.string().uuid().parse(id);
|
|
const url = new URL(req.url);
|
|
const limitRaw = url.searchParams.get("limit");
|
|
const limit = limitRaw ? z.coerce.number().int().min(1).max(100).parse(limitRaw) : 20;
|
|
const logs = await getCareLogsForScope(scope.householdId, id, limit);
|
|
return apiJson(logs);
|
|
});
|
|
}
|
|
|
|
export async function POST(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params;
|
|
return withApiHandler(request, async (scope, req) => {
|
|
z.string().uuid().parse(id);
|
|
const body: unknown = await req.json();
|
|
const parsed = careLogInput.parse({ ...(body as object), plantId: id });
|
|
const log = await logCareForScope(scope, parsed);
|
|
return apiJson(
|
|
{
|
|
id: log.id,
|
|
careType: log.careType,
|
|
notes: log.notes,
|
|
performedAt: log.performedAt.toISOString(),
|
|
performedBy: log.performedBy,
|
|
},
|
|
201,
|
|
);
|
|
});
|
|
}
|