diff --git a/src/routes/pets.ts b/src/routes/pets.ts index 51cfe23..ffe494c 100644 --- a/src/routes/pets.ts +++ b/src/routes/pets.ts @@ -12,6 +12,7 @@ import { appointments, staff, services, + sql, } from "@groombook/db"; import type { AppEnv } from "../middleware/rbac.js"; import { @@ -153,11 +154,11 @@ petsRouter.get("/:id/profile-summary", async (c) => { .limit(10); // Visit count (completed appointments) - const [{ count }] = await db - .select({ count: appointments.id }) + const [countRow] = await db + .select({ count: sql`count(*)::int` }) .from(appointments) - .where(and(eq(appointments.petId, petId), eq(appointments.status, "completed"))) - .limit(1); + .where(and(eq(appointments.petId, petId), eq(appointments.status, "completed"))); + const visitCount = countRow?.count ?? 0; // Upcoming appointment (next scheduled or confirmed) const [upcoming] = await db @@ -195,7 +196,7 @@ petsRouter.get("/:id/profile-summary", async (c) => { serviceName: h.serviceName, staffName: h.staffName, })), - visitCount: Number(count ?? 0), + visitCount, upcomingAppointment: upcoming ? { id: upcoming.id,