From 77a631945944ff165a5353d9d4332991fe488839 Mon Sep 17 00:00:00 2001 From: Flea Flicker Date: Tue, 14 Apr 2026 21:58:44 +0000 Subject: [PATCH 1/2] fix(GRO-655): create corepack cache dir in builder stage Prevents ENOENT crash in migrate and seed jobs. Root cause: corepack tries to mkdir /home/node/.cache/node/corepack/v1 but the directory does not exist in the builder stage. This was a regression in c438f57 where the cache directory was not pre-created. Co-Authored-By: Paperclip --- apps/api/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/api/Dockerfile b/apps/api/Dockerfile index fe0e0da..b8b82fe 100644 --- a/apps/api/Dockerfile +++ b/apps/api/Dockerfile @@ -12,6 +12,7 @@ RUN pnpm install --frozen-lockfile # Build FROM deps AS builder +RUN mkdir -p /home/node/.cache/node/corepack COPY packages/ packages/ COPY apps/api/ apps/api/ RUN pnpm --filter @groombook/types build && \ -- 2.52.0 From 0ed87f9ed8502d8b636f823858a41aa7c5c8187c Mon Sep 17 00:00:00 2001 From: Flea Flicker Date: Wed, 15 Apr 2026 00:12:01 +0000 Subject: [PATCH 2/2] fix(api): add server-side pagination to churn risk query (GRO-641) - Add SQL-level LIMIT/OFFSET pagination to churn risk query - Add separate COUNT(*) subquery for total without fetching all rows - Accept page and limit query params with sensible defaults and bounds - Return page, limit, and churnRiskTotal in response Co-Authored-By: Paperclip --- apps/api/src/routes/reports.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/apps/api/src/routes/reports.ts b/apps/api/src/routes/reports.ts index 3849d4c..c249862 100644 --- a/apps/api/src/routes/reports.ts +++ b/apps/api/src/routes/reports.ts @@ -286,6 +286,10 @@ reportsRouter.get("/clients", async (c) => { ninetyDaysAgo.setUTCDate(ninetyDaysAgo.getUTCDate() - 90); const ninetyDaysAgoISO = ninetyDaysAgo.toISOString(); + const page = Math.max(1, parseInt(c.req.query("page") ?? "1", 10) || 1); + const limit = Math.min(100, Math.max(1, parseInt(c.req.query("limit") ?? "20", 10) || 20)); + const offset = (page - 1) * limit; + const churnRisk = await db .select({ clientId: clients.id, @@ -298,15 +302,34 @@ reportsRouter.get("/clients", async (c) => { .having( sql`MAX(${appointments.startTime}) < ${ninetyDaysAgoISO}::timestamptz OR MAX(${appointments.startTime}) IS NULL` ) - .orderBy(sql`MAX(${appointments.startTime}) ASC NULLS FIRST`); + .orderBy(sql`MAX(${appointments.startTime}) ASC NULLS FIRST`) + .limit(limit) + .offset(offset); + + const [churnCountRow] = await db + .select({ total: sql`count(*)::int` }) + .from( + db + .select({ id: clients.id }) + .from(clients) + .leftJoin(appointments, eq(appointments.clientId, clients.id)) + .groupBy(clients.id) + .having( + sql`MAX(${appointments.startTime}) < ${ninetyDaysAgoISO}::timestamptz OR MAX(${appointments.startTime}) IS NULL` + ) + .as("churn_count") + ); + const churnRiskTotal = churnCountRow?.total ?? 0; return c.json({ from: from.toISOString(), to: to.toISOString(), newClients, activeInPeriodCount: activeInPeriod.length, - churnRisk: churnRisk.slice(0, 20), // top 20 at-risk clients - churnRiskTotal: churnRisk.length, + churnRisk, + churnRiskTotal, + page, + limit, }); }); -- 2.52.0