Data Layer medium complexity backendmobile
0
Dependencies
1
Dependents
3
Entities
0
Integrations

Description

Repository managing the current status field on expense claim records. Provides targeted read/write access for the workflow service to update claim status without requiring a full claim object. Implements optimistic locking to prevent concurrent coordinator edits from conflicting.

Feature: Threshold-Based Expense Approval Workflow

expense-claim-status-repository

Summaries

The Expense Claim Status Repository is the operational core that enables coordinators to process and manage the approval queue efficiently. By providing paginated, status-filtered views of claims across an organisation, it directly supports coordinator productivity and ensures no claim is overlooked. The optimistic locking mechanism prevents conflicting edits when multiple coordinators access the same claim simultaneously, eliminating a class of data corruption errors that would erode trust in the platform and require manual reconciliation. Fast, reliable access to claim status counts also enables real-time dashboard metrics, giving programme managers visibility into pipeline health and bottlenecks without requiring separate reporting infrastructure.

Medium complexity, this component's most significant delivery risk is the correct implementation of optimistic locking via the `updateStatus` interface, which accepts an `expectedCurrentStatus` parameter and must return a conflict error if the database value has changed since the caller last read it. This pattern requires careful integration testing under concurrent request scenarios, which should be included in the QA plan. The paginated `getPendingClaims` query will need performance testing against realistic data volumes to ensure coordinator queue load times meet UX requirements. This component is a hard dependency for the approval workflow service and the coordinator queue screen, so it sits on the critical path and should be prioritised for early completion to unblock downstream development.

This repository provides targeted, narrow-scope access to the `status` field on the `expense_claims` table, deliberately avoiding full-object reads to minimise data transfer overhead in high-frequency workflow operations. The `updateStatus` method implements optimistic concurrency control: it issues an `UPDATE ... WHERE id = claimId AND status = expectedCurrentStatus` and checks the affected row count — zero rows updated indicates a concurrent modification conflict, which must be surfaced as a typed error (`OptimisticLockConflictError`) for the calling service to handle. `getPendingClaims` and `getClaimsByStatus` must accept `organisationId` as a mandatory scope parameter and be validated against RLS policies to prevent cross-organisation data leakage.

Index coverage on `(organisation_id, status, created_at)` is required for efficient paginated queries; verify the Supabase migration includes this composite index.

Responsibilities

  • Read current status for a given claim
  • Update claim status atomically with optimistic concurrency check
  • Query claims by status for coordinator queue loading
  • Support paginated query for pending claims list

Interfaces

getStatus(claimId)
updateStatus(claimId, newStatus, expectedCurrentStatus)
getPendingClaims(organisationId, page, pageSize)
getClaimsByStatus(organisationId, status)
countByStatus(organisationId, status)

Relationships

Dependents (1)

Components that depend on this component

Related Data Entities (3)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/expense-claims 5 endpoints
GET /api/v1/expense-claims List expense claims with status/organisation filter (getPendingClaims, getClaimsByStatus)
GET /api/v1/expense-claims/:claim_id Get claim status and details (getStatus)
POST /api/v1/expense-claims Create a new expense claim
PUT /api/v1/expense-claims/:claim_id Update claim status with optimistic concurrency check (updateStatus)
DELETE /api/v1/expense-claims/:claim_id Delete a draft expense claim