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.
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { z } from "zod";
|
|
import { apiJson, withApiHandler } from "@/lib/api-handler";
|
|
import { upsertCareScheduleForScope } from "@/modules/garden/server/actions";
|
|
import { careScheduleInput } from "@/modules/garden/server/schemas";
|
|
import { getCareSchedulesForScope } 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) => {
|
|
z.string().uuid().parse(id);
|
|
const schedules = await getCareSchedulesForScope(scope.householdId, id);
|
|
return apiJson(schedules);
|
|
});
|
|
}
|
|
|
|
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 = careScheduleInput.parse({ ...(body as object), plantId: id });
|
|
const schedule = await upsertCareScheduleForScope(scope, parsed);
|
|
return apiJson(
|
|
{
|
|
id: schedule.id,
|
|
careType: schedule.careType,
|
|
intervalDays: schedule.intervalDays,
|
|
lastPerformedAt: schedule.lastPerformedAt?.toISOString() ?? null,
|
|
nextDueAt: schedule.nextDueAt?.toISOString() ?? null,
|
|
enabled: schedule.enabled,
|
|
},
|
|
201,
|
|
);
|
|
});
|
|
}
|