Files
fosterflow/src/routes/admin/pets/[id]/+layout.server.ts
T
justinandClaude Opus 4.6 63f127dfca Add admin pet detail pages: profile, photos, medical, fosters (Task 32b)
Pet layout: tabbed nav with counts for photos/medical/fosters, status
badge in header. Detail overview: summary cards and compatibility grid.
Profile: full edit form including adoption info conditional on status,
audit logged. Photos: upload, set primary (star toggle), delete, reorder
with prev/next arrows. Medical: add/delete records grouped by date,
cost stored as cents. Fosters: assign by user account (linked to
foster-role users), set current, delete, audit logged throughout.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 12:33:24 -05:00

32 lines
1.2 KiB
TypeScript

import type { LayoutServerLoad } from './$types';
import { db } from '$lib/server/db';
import { pets, petPhotos, petMedical, fosterAssignments } from '$lib/server/schema';
import { eq, count } from 'drizzle-orm';
import { error } from '@sveltejs/kit';
import { hasPermission, canViewPets } from '$lib/roles';
export const load: LayoutServerLoad = async ({ params, locals }) => {
if (!canViewPets(locals.user!.role)) error(403, 'Access denied');
const id = parseInt(params.id, 10);
if (isNaN(id)) error(404, 'Pet not found');
const [pet] = await db.select().from(pets).where(eq(pets.id, id));
if (!pet) error(404, 'Pet not found');
const [photosCount, medicalCount, fostersCount] = await Promise.all([
db.select({ total: count() }).from(petPhotos).where(eq(petPhotos.petId, id)),
db.select({ total: count() }).from(petMedical).where(eq(petMedical.petId, id)),
db.select({ total: count() }).from(fosterAssignments).where(eq(fosterAssignments.petId, id))
]);
return {
pet,
canEditPets: hasPermission(locals.user!.role, 'pets'),
counts: {
photos: photosCount[0]?.total ?? 0,
medical: medicalCount[0]?.total ?? 0,
fosters: fostersCount[0]?.total ?? 0
}
};
};