Livestock and household pets as leaves on the Location tree, mirroring Garden. - Animal model (species/breed/sex/birthdate/location, soft-delete) + AnimalLog (feeding, vet, weight, medication, breeding, acquired, died); Task.animalId for recurring care reminders - API-first /api/v1/animals (CRUD) + logs, animals:read/write scopes; animals service shared with the coming MCP - Animals pages: list grouped by species with auto-computed age, detail with facts + latest weight + care log; add/edit/remove + log entry. Nav entry. Backup/restore cover the new tables - Pure age.ts (newborn/days/months/years) with tests; verified end-to-end against a running server (create, vet + weigh-in logs, read-back) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { authenticateRequest, handleApiError } from "@/lib/api/authenticate";
|
|
import { animalUpdateInput } from "@/lib/api/schemas";
|
|
import { getAnimal, updateAnimal, deleteAnimal } from "@/lib/services/animals";
|
|
|
|
export async function GET(req: Request, { params }: { params: { id: string } }) {
|
|
try {
|
|
const ctx = await authenticateRequest(req, "animals:read");
|
|
return NextResponse.json(await getAnimal(ctx, params.id));
|
|
} catch (err) {
|
|
return handleApiError(err);
|
|
}
|
|
}
|
|
|
|
export async function PATCH(req: Request, { params }: { params: { id: string } }) {
|
|
try {
|
|
const ctx = await authenticateRequest(req, "animals:write");
|
|
const input = animalUpdateInput.parse(await req.json());
|
|
return NextResponse.json(await updateAnimal(ctx, params.id, input));
|
|
} catch (err) {
|
|
return handleApiError(err);
|
|
}
|
|
}
|
|
|
|
export async function DELETE(req: Request, { params }: { params: { id: string } }) {
|
|
try {
|
|
const ctx = await authenticateRequest(req, "animals:write");
|
|
await deleteAnimal(ctx, params.id);
|
|
return NextResponse.json({ ok: true });
|
|
} catch (err) {
|
|
return handleApiError(err);
|
|
}
|
|
}
|