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>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user