feat(orders): implement order ingestion pipeline, review ratings schema, and [Family] exclusion

This commit is contained in:
2026-07-26 18:52:34 +10:00
parent d06088fe34
commit bbb90238e4
13 changed files with 667 additions and 3 deletions
+9 -2
View File
@@ -71,12 +71,19 @@ export const myShare = (participant = "$1") => `COALESCE(
export const mySplitOf = (base: string, participant = "$1") =>
`((${base}) * ${myShare(participant)} / 100)`;
export const NON_BUDGET_TAGS = ['family'];
export const EXCLUDE_NON_BUDGET_TAGS = `NOT EXISTS (
SELECT 1 FROM transaction_tags tt JOIN tags tg ON tg.id = tt.tag_id
WHERE tt.transaction_id = t.id AND tg.name = ANY(ARRAY['family'])
)`;
/**
* Predicate excluding categories that are not spend.
* Predicate excluding categories and tags that are not spend.
* The COALESCE matters: a bare `category NOT IN (...)` evaluates to NULL for
* uncategorised rows, which silently drops them from spend totals.
*/
export const EXCLUDE_NON_SPEND = `${EFFECTIVE_CATEGORY} NOT IN ('transfers', 'investment', 'income')`;
export const EXCLUDE_NON_SPEND = `${EFFECTIVE_CATEGORY} NOT IN ('transfers', 'investment', 'income') AND ${EXCLUDE_NON_BUDGET_TAGS}`;
/**
* Rows that count towards NET spend — outgoings plus the refunds that cancel