fix(merchants): page crashed on an uncategorised transaction
ci / lint-test (push) Successful in 38s
ci / lint-test (push) Successful in 38s
Regression from the analytics scoping work. Chain:
1. Three transactions have a NULL category. The old WHERE clause
`COALESCE(o.category_override, t.category) NOT IN ('transfers','investment')`
evaluated to NULL for those rows, so they were silently dropped — which is
the bug EXCLUDE_NON_SPEND fixed by defaulting to 'other'.
2. Including them exposed that the SELECT still used the non-null-safe
COALESCE, so MODE() returned NULL for the affected merchant
("Shared expenses carryover (SplitMyExpenses)", a manual transaction that
the LEFT JOIN fix also newly included).
3. formatCategory(null) threw "Cannot read properties of null (reading
'split')" and took down the whole page render.
Fixed at both layers:
- Both merchants routes now use the EFFECTIVE_CATEGORY fragment, so the API
cannot emit a null category.
- formatCategory tolerates null/undefined and returns "Uncategorised". An
uncategorised transaction should never be able to crash a page.
Verified against the live DB: 200 merchants, zero null categories, and
/merchants /transactions /insights /budget /statements all render 200.
This commit is contained in:
@@ -36,7 +36,10 @@ export const CATEGORIES = [
|
||||
|
||||
export type Category = (typeof CATEGORIES)[number];
|
||||
|
||||
export function formatCategory(cat: string): string {
|
||||
// Tolerates null/undefined: an uncategorised transaction must never be able to
|
||||
// crash a page that renders its category.
|
||||
export function formatCategory(cat: string | null | undefined): string {
|
||||
if (!cat) return "Uncategorised";
|
||||
return cat
|
||||
.split("_")
|
||||
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
||||
|
||||
Reference in New Issue
Block a user