Skip to content

feat(billing): back disputes router with Postgres repository (#1243) - #1480

Open
lienhoatienphung-svg wants to merge 1 commit into
CalloraOrg:mainfrom
lienhoatienphung-svg:feat/1243-back-disputes-with-postgres-repository
Open

lienhoatienphung-svg wants to merge 1 commit into
CalloraOrg:mainfrom
lienhoatienphung-svg:feat/1243-back-disputes-with-postgres-repository

Conversation

@lienhoatienphung-svg

Copy link
Copy Markdown

Summary

Backs the billing disputes subsystem with a PostgreSQL repository (PgDisputeRepository), mounts /api/billing/disputes in src/app.ts, and ensures dispute state and audit trails survive process restarts and work across replicas.

Closes #1243

Key Changes

  1. PostgreSQL Repository (src/services/disputeService.ts):
    • Implemented PgDisputeRepository against migrations/0019_disputes.sql (disputes and dispute_events tables), using transactional BEGIN / COMMIT / ROLLBACK writes when available.
    • Updated DisputeRepository interface and DisputeService with MaybePromise<T> chaining so synchronous InMemoryDisputeRepository callers remain synchronous while async PgDisputeRepository callers return Promises.
  2. Async Route Handlers & App Mounting (src/routes/billing/disputes.ts, src/app.ts):
    • Updated /api/billing/disputes route handlers to await DisputeService operations.
    • Mounted /api/billing/disputes in src/app.ts backed by new PgDisputeRepository(pool) in non-test environments (falling back to InMemoryDisputeRepository in unit test mode when not overridden).
  3. Standard SQL Migration (migrations/0019_disputes.sql):
    • Normalized DDL identifiers and added resolution_notes on disputes and notes on dispute_events so the migration applies cleanly in both PostgreSQL (pg / pg-mem) and SQLite.

Verification

  • Added pg-mem integration tests in src/routes/billing/disputes.test.ts covering persistence across fresh DisputeService instances, audit trail creation/status updates, and 409 Conflict on duplicate open disputes.
  • Verified with npx jest src/routes/billing/disputes.test.ts (44/44 passed).

Payout Wallet (Base Mainnet USDC)

0x3806cd592a508d1992Ed007C2F53de251C2E7452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Back disputes with a Postgres repository

1 participant