refactor(backend): inline single-use util layers (#1257)

Merged
LU
6mo ago
+92-564

Closes #1257.

  • migrate artists.ts from wrapHandler to asyncHandler + global error middleware; delete routeUtils.wrapHandler
  • inline isDeveloperUser into requireAdmin; delete utils/developerAccess.ts
  • extract one shared stripUnknownFields helper across the three validators in middleware/validate.ts
  • asyncHandler now returns the promise it chains (return result.catch(next)) — no runtime behavior change (express ignores handler return values), makes the wrapper awaitable in tests
  • removed 19 artists unit tests that asserted wrapHandler middleware behavior now covered by integration tests; 11 handler-logic tests kept

Verification: backend type:check pass; backend suite 67 suites / 992 tests pass.


Summary by cubic

Refactors backend routing to use asyncHandler with global error handling and inlines developer access logic into requireAdmin. Removes two single-use utils and keeps API behavior unchanged while making handlers easier to test.

  • Refactors

    • Migrate artists route handlers from wrapHandler to asyncHandler; remove utils/routeUtils.ts.
    • Inline isDeveloperUser into requireAdmin; remove utils/developerAccess.ts (including requireDeveloperUser); update auth to import from middleware.
    • Make asyncHandler return its promise (awaitable in tests); no runtime behavior change.
  • Tests

    • Drop middleware-behavior unit tests in artists.test.ts now covered by integration; keep handler-logic tests.
    • Update tests to mock requireAdmin, pass next to handlers, and import isDeveloperUser from middleware.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed async middleware to properly return promise rejection results.
  • Refactor

    • Consolidated developer access verification logic into the middleware module.
    • Refactored route handler architecture for improved consistency and maintainability.