refactor(backend): inline single-use util layers (#1257)
Merged
LU
6mo ago+92+92+01234567890123456789-564-564-012345678901234567890123456789
Closes #1257.
- migrate
artists.tsfromwrapHandlertoasyncHandler+ global error middleware; deleterouteUtils.wrapHandler - inline
isDeveloperUserintorequireAdmin; deleteutils/developerAccess.ts - extract one shared
stripUnknownFieldshelper across the three validators inmiddleware/validate.ts asyncHandlernow 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.