Standardize wallet limits, error envelope, and Prisma migration hygiene - #654
Merged
Conversation
|
@Dannyswiss1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…lope-and-Prisma-migration-hygiene
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #502
Closes #503
Closes #514
Closes #523.
#502 — Replace legacy user limits with wallet scoped limits
WalletLimit(Prisma model),LimitsService, andLimitsControlleralready implement full wallet-scoped CRUD with soft-delete, domain events, metrics, and OpenAPI docs; legacyUserLimit/LegacyUserare unreferenced outsideschema.prisma.limits.controller.tsreferencingUpdateLimitsDtoin a@ApiBodydecorator without importing it — aReferenceErrorthat crashed the module at load time.payments-limits.integration.spec.ts, which failed to instantiatePaymentsServicebecausePaymentMetricsService/ConfigServiceproviders were never added after those constructor deps were introduced.limits.service.spec.tsthat no longer matched the real implementation (asserted harddeleteinstead of soft-delete, referenced an undefinedcacheService, missingtransaction.findManymocks forremainingDailyLimit).#503 — Create spending limits with Prisma transactions
LimitsService.setLimitsnow wraps its read-then-write (findUnique+upsert) in a singleprisma.$transaction(...), closing a race window where two concurrentsetLimitscalls for the same wallet could read the same "existing" state and emit incorrectlimit.updateddiffs.POST /wallets/:walletId/limitsto document the atomicity guarantee.#514 — Standardize structured API error responses
HttpExceptionFilterwas never registered — noapp.useGlobalFilters()call existed anywhere, so real requests bypassed it entirely. Wired it intomain.ts.errorCodefrom exception bodies (e.g.LimitExceededException'sLIMIT_PER_TX_EXCEEDED) even though the limits controller's own OpenAPI examples document it. AddederrorCodetoErrorResponseand the parsing logic.README.md.#523 — Normalize Prisma migration docs and CI check
prisma/migrations/network_scoped_api_keys.sqlsitting as a loose file directly underprisma/migrations/— Prisma silently ignores anything not inside a migration folder, so theApiKey.networkcolumn already declared inschema.prismahad no migration that actually created it (and the stray file used the wrong type,TEXTinstead of theWalletNetworkenum). Moved it into a proper20260730000000_add_network_scoped_api_keys/migration.sqlwith the corrected enum type.scripts/check-migration-naming.ts: validates no loose files besidesmigration_lock.toml, every folder has amigration.sql, names match<14-digit-timestamp>_<snake_case>, and no duplicate timestamps — with a documentedLEGACY_EXCEPTIONSallowlist for pre-existing folders already applied to real databases..github/workflows/ci.yml), plus a scoped Jest config (scripts/jest.config.js) for the checker's own unit tests.docs/PRISMA-MIGRATIONS.mddocumenting the convention.Test plan
pnpm test— all touched suites pass (limits.service.spec.ts,limits.controller.spec.ts,payments-limits.integration.spec.ts,http-exception.filter.spec.ts)pnpm run test:scripts— 8/8 passing for the new migration-naming checkerpnpm run prisma:check-migrations— passes against current repo statenpx prisma validate— schema validtsc --noEmitclean on all touched files