Skip to content

14.3: Generic Budget Service Factory #498

@steilerDev

Description

@steilerDev

As a developer, I want a generic budget service factory that encapsulates shared CRUD and validation logic so that the duplicated budget service code is consolidated while preserving entity-specific invoice handling.

Parent Epic: #495 (EPIC-14: Cross-Entity Code Deduplication & UI Harmonization)
Priority: Should Have
Complexity: Large

Acceptance Criteria

  • 1. A generic budget service factory exists (e.g., createBudgetService(config)) that accepts entity-specific configuration and returns a fully typed budget service
  • 2. Shared CRUD operations (create budget line, update budget line, delete budget line, get budget lines, get budget summary) are implemented once in the factory
  • 3. Entity-specific invoice handling is pluggable — the factory accepts an optional invoice handler configuration that differs between Work Items and Household Items
  • 4. workItemBudgetService is refactored to use the factory with work-item-specific invoice handling
  • 5. householdItemBudgetService is refactored to use the factory with household-item-specific invoice handling
  • 6. Budget validation logic (confidence level rules, amount constraints, vendor existence checks) is defined once in the factory, not duplicated
  • 7. The combined line count of the two budget service files plus the factory is at least 30% less than the original two files combined
  • 8. All existing budget API endpoints return identical responses before and after the refactor
  • 9. All existing unit and integration tests pass without modification
  • 10. Budget route handlers (workItemBudgets.ts, householdItemBudgets.ts) are simplified to use the shared factory outputs — duplicated route-level validation or transformation logic is also reduced

Notes

  • Blocked by: 14.1: Shared Backend Converters & Validators #496 (Story 14.1 — shared validators are used within budget services)
  • Key source files:
    • server/src/services/workItemBudgetService.ts (55-65% overlap with HI version)
    • server/src/services/householdItemBudgetService.ts
    • server/src/routes/workItemBudgets.ts (~90% overlap with HI route handler)
    • server/src/routes/householdItemBudgets.ts
  • The budget services have more entity-specific divergence than subsidy services (invoice linking, budget source concepts) — the factory must support pluggable behavior for these areas
  • Can be developed in parallel with Story 14.2 (Subsidy Factory) after Story 14.1 is complete

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions