From 5dc9c49132055024d4ef6dadfd11f15e792cfb2b Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Tue, 14 Jul 2026 12:41:00 +0000 Subject: [PATCH] fix(reporting): quote the camelCase aliases on the EPC coverage query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The card rendered a blank value and "NaN%": Postgres returns column names verbatim, so `AS without_epc` came back as `without_epc` while the code read `withoutEpc` — undefined, and `undefined / total * 100` is NaN. `db.execute()` asserts the row shape rather than checking it, so tsc, lint and the full suite all passed on the broken query. The previous field names (`estimated`, `actual`) were single words and happened to survive the round trip; renaming to camelCase did not. Quoted aliases are the existing convention (see utils.ts). Verified against portfolio 839: keys come back as [withoutEpc, withEpc], and the card renders 29 / "0.5% have no EPC on record". Co-Authored-By: Claude Opus 4.8 (1M context) --- .../[slug]/(portfolio)/reporting/databaseFunctions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/portfolio/[slug]/(portfolio)/reporting/databaseFunctions.ts b/src/app/portfolio/[slug]/(portfolio)/reporting/databaseFunctions.ts index ebf92543..725c1f95 100644 --- a/src/app/portfolio/[slug]/(portfolio)/reporting/databaseFunctions.ts +++ b/src/app/portfolio/[slug]/(portfolio)/reporting/databaseFunctions.ts @@ -147,8 +147,8 @@ export async function getEpcCoverageCounts( ): Promise { const result = await db.execute(sql` SELECT - SUM(CASE WHEN ${withoutEpcSql(sql`e`)} = true THEN 1 ELSE 0 END)::int AS without_epc, - SUM(CASE WHEN ${withoutEpcSql(sql`e`)} = false THEN 1 ELSE 0 END)::int AS with_epc + SUM(CASE WHEN ${withoutEpcSql(sql`e`)} = true THEN 1 ELSE 0 END)::int AS "withoutEpc", + SUM(CASE WHEN ${withoutEpcSql(sql`e`)} = false THEN 1 ELSE 0 END)::int AS "withEpc" FROM property p LEFT JOIN property_details_epc e ON e.property_id = p.id ${newApproachJoins}