Service Layer medium complexity mobilebackend
0
Dependencies
0
Dependents
4
Entities
0
Integrations

Description

Core business-logic service that creates, validates, and syncs expense records. Evaluates auto-approval eligibility by checking the configured kilometre threshold and receipt attachment status before persisting to the local Drift database and enqueuing for backend sync. Handles optimistic writes with rollback on sync failure.

Feature: Travel Expense Registration

expense-service

Sources & reasoning

Auto-approval logic must live in the service layer so it can be evaluated server-side for integrity while also being available offline for UX feedback. The service encapsulates the threshold check and routes approved claims directly vs queuing others for coordinator attestation.

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

Responsibilities

  • Validate expense draft against business rules (type exclusivity, required fields)
  • Evaluate auto-approval eligibility (km < threshold AND no receipts required)
  • Persist expense to local Drift database via expenses data component
  • Enqueue sync mutation to Mutation Outbox Service
  • Fetch organisation-scoped auto-approval threshold from configuration

Interfaces

submitExpense(draft: ExpenseDraft): Future<Expense>
getAutoApprovalEligibility(draft: ExpenseDraft): bool
getExpenses(userId: String): Future<List<Expense>>
syncPendingExpenses(): Future<void>
getApprovalThreshold(orgId: String): Future<int>