Skip to content

fix: replace as any casts in admin, backup, search, and transactions - #1172

Merged
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
shadrackmanfred:fix/1084-as-any-casts
Sep 1, 2026
Merged

fix: replace as any casts in admin, backup, search, and transactions#1172
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
shadrackmanfred:fix/1084-as-any-casts

Conversation

@shadrackmanfred

Copy link
Copy Markdown
Contributor

Summary

Replaces every as any cast in the four modules named in the issue (admin, backup, search, transactions) with real Prisma types, declared DTOs, or locally defined shapes, so contract drift fails compilation instead of exploding at runtime.

as any count before/after:

Scope Before After
Four modules (including in-module specs) 58 0
Repository-wide (src/) 171 113

What changed, by module

  • admincursor was being read off the query DTOs via (query as any).cursor. The three pagination DTOs (AdminUsersQueryDto, ModerationQueueQueryDto, TransactionMonitoringQueryDto) now declare cursor?: string (validated), and the service reads query.cursor directly. The items[items.length - 1] casts were unnecessary and are removed.
  • backup — string literals like 'RUNNING' as any replaced with the real Prisma enum constants (BackupStatus.RUNNING, RestoreStatus.RUNNING/COMPLETED/FAILED, BackupTrigger.MANUAL/SCHEDULED). Runtime values are identical (string enums).
  • search — the (this.prisma as any). access on property / searchHistory / popularSearch / $queryRaw removed (all delegates exist on the generated client, verified in node_modules/.prisma/client). The $queryRaw location query is now typed with its declared row shape (Array<{ city; state; zip_code }>) instead of returning unknown.
  • transactions
    • transaction-reminders: MilestoneStatus.PENDING instead of 'PENDING' as any; the where-object cast removed; prefs?.optOutReminders (the field exists on UserPreferences) instead of (prefs as any)?.optOutReminders.
    • transactions.service: cursor added to TransactionListQueryDto; the (query as any).cursor read is now query.cursor.
    • disputes.controller: @Roles(UserRole.ADMIN) instead of @Roles('ADMIN' as any).
    • transaction-audit.service: the status column is a TransactionStatus enum, but log() accepted an arbitrary string and cast it. The parameter is now typed TransactionStatus and the caller passes the transitioned-to status. Note: the old 'STATUS_TRANSITION' literal was not a valid enum member, so Prisma would reject that row at runtime — this refactor also fixes that latent failure.
  • specs — mock literals typed via MockPrisma-style interfaces or jest.Mocked<Partial<…>>; the six } as any object casts in search.service.spec.ts, two in backup.service.spec.ts, and five string/enum casts in transactions.service.spec.ts are gone.

Verification

  • npx tsc --noEmit — no new errors vs main (the 2 baseline errors in untouched files remain)
  • npm test — 96 tests across src/admin, src/backup, src/search, src/transactions, test/admin, test/backup, test/transactions all pass

Closes #1084

Remove every `as any` cast in the four modules (58 sites including
specs; repository-wide count drops 171 -> 113) so contract drift
surfaces at compile time instead of at runtime.

- admin: declare the cursor query param on the pagination DTOs and use
  it directly; remove the last-item index casts
- backup: use the real BackupStatus/BackupTrigger/RestoreStatus enum
  constants instead of string literals cast to any
- search: drop the prisma delegate casts (models exist on the client)
  and type the $queryRaw location query with its row shape
- transactions: type milestone status with MilestoneStatus, add cursor
  to TransactionListQueryDto, use UserRole.ADMIN for @roles, and
  narrow the audit log status to TransactionStatus (the previous
  'STATUS_TRANSITION' literal was rejected by the DB enum at runtime)
- specs: type prisma/service mocks with interfaces or Partial mocks
  instead of casting literals to any
@drips-wave

drips-wave Bot commented Sep 1, 2026

Copy link
Copy Markdown

@shadrackmanfred 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! 🚀

Learn more about application limits

@nanaf6203-bit
nanaf6203-bit merged commit 812114f into MettaChain:main Sep 1, 2026
4 of 7 checks passed
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.

Replace unchecked as-any casts in admin, backup, search, and transactions modules

2 participants