Skip to content

Add a settlement reconciliation discrepancy report endpoint backed by jobs/settlementReconciler.ts #642

Description

@Baskarayelu

📋 Description

The settlement reconciler in src/jobs/settlementReconciler.ts (tested in src/jobs/settlementReconciler.test.ts) compares the payouts table against the Horizon ledger and detects discrepancies, but there is no operator endpoint to retrieve the latest reconciliation result for triage.

This issue adds a read-only admin endpoint that returns the most recent reconciliation run's summary and the list of unmatched records, with cursor pagination.

Why this matters: reconciliation that runs in the dark forces operators to read logs during incidents. A queryable discrepancy report makes settlement drift actionable.

🎯 Requirements & Context

Functional requirements

  • Add GET /api/admin/settlement/reconciliation under src/routes/admin, RBAC-gated.
  • Persist reconciliation run summaries (matched count, unmatched count, run timestamp) and unmatched records.
  • Return a paginated discrepancy list using the shared cursor envelope from src/lib/pagination.ts.
  • Validate query params with zod; return the standard response envelope.
  • Export a prom-client gauge for current unmatched count.

Context & constraints

  • Endpoint is read-only; never mutates payout records.
  • Reuse the reconciler's existing result types rather than re-deriving discrepancies in the route.

🛠️ Suggested Execution

1. Fork & branch

git checkout -b feat/settlement-reconciliation-report

2. Implement changes

  • Persist run results; add the route, zod schema, pagination, and gauge.
  • Add TSDoc + a zod-to-openapi annotation.
  • Add supertest tests for empty, matched-only, and discrepancy-present runs plus RBAC.

3. Test & commit

npm run test -- settlementReconcil
npm run lint
npm run build
  • Edge cases: no run yet, large unmatched set spanning multiple pages, non-admin caller.

Example commit message

feat(settlement): expose reconciliation discrepancy report endpoint

Persists settlementReconciler results and serves a paginated, RBAC-gated
report at GET /api/admin/settlement/reconciliation.

✅ Acceptance Criteria & Guidelines

Requirement Target
Read-only paginated RBAC report Required
Unmatched-count gauge Required
Supertest coverage incl. discrepancy path ≥ 95% of route branches
npm run lint + npm run build clean Required
Timeframe 96 hours from assignment

💬 Community & Support

Questions and design discussion — join the GrantFox contributor community on Discord: https://discord.gg/nmnPBkBge

Please comment on this issue to ask to be assigned before you start. 🚀

Metadata

Metadata

Assignees

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions