Service Layer medium complexity backend
0
Dependencies
0
Dependents
3
Entities
0
Integrations

Description

Backend service that manages CRUD operations for approval_rules and evaluates submitted expense claims against the organization's active rules at submission time. Returns auto_approved status and writes an expense_approvals record with approver_type = system when a matching rule is found, ordered by rule specificity.

Feature: Auto-Approval Rules

approval-rules-service

Sources & reasoning

Core business logic for this feature. The evaluation loop that runs on every expense submission - checking org-specific rules ordered by specificity and writing system-authored approvals - must be isolated in a dedicated service to keep the expense submission handler clean and to allow the config UI to call the same preview query.

No source references — this artifact was included based on reasoning alone (see above).

Responsibilities

  • Load active approval rules for an organization ordered by specificity
  • Evaluate an expense claim against each candidate rule and return the first match
  • Write expense_approvals row with approver_type = system on auto-approval
  • Provide CRUD endpoints for rule management consumed by the config UI
  • Serve live-preview aggregation query for matching recent claims against a draft rule

Interfaces

createRule(orgId: string, draft: ApprovalRuleDraft): Promise<ApprovalRule>
updateRule(ruleId: string, patch: Partial<ApprovalRuleDraft>): Promise<ApprovalRule>
deleteRule(ruleId: string): Promise<void>
setRuleEnabled(ruleId: string, enabled: boolean): Promise<void>
listRules(orgId: string): Promise<ApprovalRule[]>
evaluateExpense(expense: ExpenseClaim, orgId: string): Promise<ApprovalDecision>
previewRuleMatch(draft: ApprovalRuleDraft, orgId: string): Promise<PreviewResult>

Related Data Entities (3)

Data entities managed by this component