Skip to content

Rules, import and analytics by category id + rule backfill (#91, 2/5) - #229

Draft
NotThaDev wants to merge 6 commits into
feature/91-categories-apifrom
feature/91-rules-analytics
Draft

NotThaDev wants to merge 6 commits into
feature/91-categories-apifrom
feature/91-rules-analytics

Conversation

@NotThaDev

Copy link
Copy Markdown
Owner

Part 2 of 5 for #91, stacked on #227.

What

  • Rules:
    • Category conditions take a category id (system or own custom); a legacy enum name is still accepted.
    • Skip checks and apply/preview compare ids, so a custom target applies.
    • Preview items add oldCategoryId/newCategoryId.
  • Import: defaultCategoryId (it wins over the legacy defaultCategory; a foreign id gives 400). Rule targets are applied as ids.
  • Analytics: grouped by categoryId.
    • Custom categories count as income or expense by Kind; system categories keep the existing enum logic.
    • Legacy string fields stay ("Other" for custom ids). Monthly income adds a categoryIds map.
  • POST /api/maintenance/backfill-rule-categories: one-time job that converts stored condition names to ids.
    • Header X-Backfill-Key is checked against Backfill:Key (env Backfill__Key) with a constant-time compare. 404 when no key is configured, 401 when the key is wrong.
    • Idempotent; returns { scanned, updated }.

Why

  • The JSON contract stays compatible, so today's frontend keeps working.
  • Run the backfill only after PR 3 is deployed. The current rules page shows a converted condition as a raw id (category = 2). This is noted in the backend README.

Tested

  • dotnet test: 183/183 (8 new: matcher by id/name/custom, foreign id rejected, apply to a custom target, import default, analytics by Kind, backfill 404/401/convert/idempotent).
  • Build and format clean; frontend lint and build pass.
  • Worktree API + frontend on an isolated Postgres DB:
    • income analytics count the custom +50 (categoryId 1000, category "Other");
    • backfill: 401 without the key, then converted "Food" → "2" in the jsonb, and a second run updated 0;
    • dashboard, transactions, analytics and rules pages render with no console errors; no horizontal scroll at 375 px.

Out of scope

🤖 Generated with Claude Code

…ill (#91)

Rule conditions accept a category id or a legacy enum name; skip checks compare ids.
Import takes defaultCategoryId. Analytics group by category id and count custom
categories by Kind, with legacy string fields kept. POST
/api/maintenance/backfill-rule-categories converts stored condition names to ids
(Backfill:Key header, idempotent).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant