From 3ce58d4c571ff9ae2601d306900dac2655c9c62b Mon Sep 17 00:00:00 2001 From: ghost2023 Date: Fri, 21 Aug 2026 15:51:05 +0300 Subject: [PATCH] refactor(reports): label revenue categories from a key column CATEGORY_LABEL_EXPR wraps the classifying CASE, so it only works where the classification happens in the same SELECT. A report that classifies in a subquery and labels in the wrapper has a plain key column to label instead. CATEGORY_LABEL_OF takes that key expression; CATEGORY_LABEL_EXPR is now defined through it, so its three existing callers are unchanged. Mirrors CATEGORY_LABEL_OF in operations-classification.ts. Claude-Session: https://claude.ai/code/session_01LoY3hNWqcaAC1pYmGPN7jr --- .../src/modules/reports/revenue-classification.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/edr-freight-api/src/modules/reports/revenue-classification.ts b/apps/edr-freight-api/src/modules/reports/revenue-classification.ts index 526e35add..7beb79334 100644 --- a/apps/edr-freight-api/src/modules/reports/revenue-classification.ts +++ b/apps/edr-freight-api/src/modules/reports/revenue-classification.ts @@ -139,8 +139,15 @@ const labelCase = (expr: string, options: ReportFilterOption[]): string => .map((o) => `WHEN '${o.value}' THEN '${o.label.replace(/'/g, "''")}'`) .join('\n ')}\nEND`; +/** + * The same labelling applied to a key that is already a column — for reports + * that classify in a subquery and label in the wrapper. + */ +export const CATEGORY_LABEL_OF = (keyExpr: string): string => + labelCase(keyExpr, REVENUE_CATEGORIES); + /** The category as a business label rather than its key, for display columns. */ -export const CATEGORY_LABEL_EXPR = labelCase(REVENUE_CATEGORY_EXPR, REVENUE_CATEGORIES); +export const CATEGORY_LABEL_EXPR = CATEGORY_LABEL_OF(REVENUE_CATEGORY_EXPR); /** * Period-over-period change, as a percentage.