Skip to content

feat: implement settlements repository (#17)#91

Open
Chucks1093 wants to merge 2 commits intoCalloraOrg:mainfrom
Chucks1093:feat/settlements-repository-17
Open

feat: implement settlements repository (#17)#91
Chucks1093 wants to merge 2 commits intoCalloraOrg:mainfrom
Chucks1093:feat/settlements-repository-17

Conversation

@Chucks1093
Copy link

Closes #17

Summary

Implements a complete settlements persistence layer with Prisma, including schema, migration, repository methods, and isolated unit tests.

Changes

  • Added prisma/schema.prisma with:
    • Settlement model
    • SettlementStatus enum: pending | completed | failed
  • Added Prisma migration to create the settlements table with indexes on:
    • developerId
    • status
  • Added src/db.ts as a Prisma client singleton
  • Added SettlementRepository with all required methods:
    • create(developerId, amountUsdc, status)
    • findById(id)
    • listByDeveloper(developerId, limit, offset)
    • updateStatus(id, status, txHash)
      • Enforces txHash for completed
      • Sets completedAt and stellarTxHash on completion
      • Clears completion metadata for non-completed statuses
    • getPendingSettlementTotal(developerId)
      • Returns decimal string total
      • Returns "0" when no pending settlements exist
  • Renamed jest.config.js to jest.config.cjs to resolve ESM/CJS config loading conflict

Testing

  • Added full unit test coverage using jest-mock-extended (no real DB required)
  • Covered:
    • Create behavior (default and explicit statuses)
    • findById found/not-found paths
    • listByDeveloper pagination and ordering
    • updateStatus transitions and validation edge cases
    • Aggregate behavior in getPendingSettlementTotal including empty/null sums
  • Verified locally:
    • npm run typecheck
    • npm test

@Chucks1093
Copy link
Author

@greatest0fallt1me please can you quickly merge this .thanks

@greatest0fallt1me
Copy link
Contributor

please resolve the conflicts

- Add Prisma schema with Settlement model and SettlementStatus enum
- Add migration creating settlements table with indexes on developerId and status
- Add SettlementRepository with create, findById, listByDeveloper, updateStatus, getPendingSettlementTotal
- Inject PrismaClient via constructor for testability
- Add full unit tests with jest-mock-extended covering all methods and edge cases
- Rename jest.config.js to jest.config.cjs to fix ESM/CJS conflict
@Chucks1093 Chucks1093 force-pushed the feat/settlements-repository-17 branch from 1bee534 to cb287e3 Compare February 26, 2026 10:15
@Chucks1093
Copy link
Author

@greatest0fallt1me

@greatest0fallt1me
Copy link
Contributor

@Chucks1093 Can you resolve the conflicts?

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.

Implement Settlements Repository

2 participants