24 lines
976 B
TypeScript
24 lines
976 B
TypeScript
import { apiJson, withApiHandler } from "@/lib/api-handler";
|
|
import { createPlantForScope } from "@/modules/garden/server/actions";
|
|
import { plantInput } from "@/modules/garden/server/schemas";
|
|
import { getPlantForScope, listPlantsForScope } from "@/modules/garden/server/queries";
|
|
|
|
export async function GET(request: Request) {
|
|
return withApiHandler(request, async (scope, req) => {
|
|
const url = new URL(req.url);
|
|
const containerId = url.searchParams.get("containerId") ?? undefined;
|
|
const plants = await listPlantsForScope(scope.householdId, { containerId });
|
|
return apiJson(plants);
|
|
});
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
return withApiHandler(request, async (scope, req) => {
|
|
const body: unknown = await req.json();
|
|
const parsed = plantInput.parse(body);
|
|
const plant = await createPlantForScope(scope, parsed);
|
|
const detail = await getPlantForScope(scope.householdId, plant.id);
|
|
return apiJson(detail, 201);
|
|
});
|
|
}
|