Merge pull request 'fix(api): repair root src/routes/pets.ts visit-count query (GRO-1945)' (#107) from flea/GRO-1945-pets-visitcount-hotfix into dev
CI / Test (push) Successful in 10s
CI / Lint & Typecheck (push) Successful in 14s
CI / Build & Push Docker Images (push) Successful in 21s
CI / Test (pull_request) Successful in 10s
CI / Lint & Typecheck (pull_request) Successful in 15s
CI / Build & Push Docker Images (pull_request) Successful in 59s
CI / Test (push) Successful in 10s
CI / Lint & Typecheck (push) Successful in 14s
CI / Build & Push Docker Images (push) Successful in 21s
CI / Test (pull_request) Successful in 10s
CI / Lint & Typecheck (pull_request) Successful in 15s
CI / Build & Push Docker Images (pull_request) Successful in 59s
This commit was merged in pull request #107.
This commit is contained in:
+6
-5
@@ -12,6 +12,7 @@ import {
|
|||||||
appointments,
|
appointments,
|
||||||
staff,
|
staff,
|
||||||
services,
|
services,
|
||||||
|
sql,
|
||||||
} from "@groombook/db";
|
} from "@groombook/db";
|
||||||
import type { AppEnv } from "../middleware/rbac.js";
|
import type { AppEnv } from "../middleware/rbac.js";
|
||||||
import {
|
import {
|
||||||
@@ -153,11 +154,11 @@ petsRouter.get("/:id/profile-summary", async (c) => {
|
|||||||
.limit(10);
|
.limit(10);
|
||||||
|
|
||||||
// Visit count (completed appointments)
|
// Visit count (completed appointments)
|
||||||
const [{ count }] = await db
|
const [countRow] = await db
|
||||||
.select({ count: appointments.id })
|
.select({ count: sql<number>`count(*)::int` })
|
||||||
.from(appointments)
|
.from(appointments)
|
||||||
.where(and(eq(appointments.petId, petId), eq(appointments.status, "completed")))
|
.where(and(eq(appointments.petId, petId), eq(appointments.status, "completed")));
|
||||||
.limit(1);
|
const visitCount = countRow?.count ?? 0;
|
||||||
|
|
||||||
// Upcoming appointment (next scheduled or confirmed)
|
// Upcoming appointment (next scheduled or confirmed)
|
||||||
const [upcoming] = await db
|
const [upcoming] = await db
|
||||||
@@ -195,7 +196,7 @@ petsRouter.get("/:id/profile-summary", async (c) => {
|
|||||||
serviceName: h.serviceName,
|
serviceName: h.serviceName,
|
||||||
staffName: h.staffName,
|
staffName: h.staffName,
|
||||||
})),
|
})),
|
||||||
visitCount: Number(count ?? 0),
|
visitCount,
|
||||||
upcomingAppointment: upcoming
|
upcomingAppointment: upcoming
|
||||||
? {
|
? {
|
||||||
id: upcoming.id,
|
id: upcoming.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user