Explorar o código

fix: resolve type errors in legacy alias middleware

fszontagh hai 3 meses
pai
achega
b37492f482
Modificáronse 2 ficheiros con 3 adicións e 3 borrados
  1. 2 2
      src/api/middleware/legacyShopAlias.ts
  2. 1 1
      src/api/routes.ts

+ 2 - 2
src/api/middleware/legacyShopAlias.ts

@@ -42,12 +42,12 @@ export function rewriteKeys(value: unknown): unknown {
  * Express middleware that monkey-patches res.json() to rewrite response keys
  * Express middleware that monkey-patches res.json() to rewrite response keys
  * from site-based naming back to shop-based naming for backward compatibility.
  * from site-based naming back to shop-based naming for backward compatibility.
  */
  */
-export function legacyShopAlias(req: Request, res: Response, next?: NextFunction): void {
+export function legacyShopAlias(_req: Request, res: Response, next?: NextFunction): void {
   const originalJson = res.json.bind(res);
   const originalJson = res.json.bind(res);
 
 
   res.json = function (body?: any): Response {
   res.json = function (body?: any): Response {
     return originalJson(rewriteKeys(body));
     return originalJson(rewriteKeys(body));
   };
   };
 
 
-  next?.();
+  if (next) next();
 }
 }

+ 1 - 1
src/api/routes.ts

@@ -83,7 +83,7 @@ export function createRouter(jobQueue: JobQueue, apiKey: string, db?: SiteDataba
       .replace(/\/sites\b/g, '/shops')
       .replace(/\/sites\b/g, '/shops')
       .replace(/:siteId\b/g, ':id');
       .replace(/:siteId\b/g, ':id');
 
 
-    const legacyMiddleware = [legacyShopAlias, ...(endpoint.middleware || [])];
+    const legacyMiddleware: Array<(req: any, res: any, next?: any) => void | Promise<void>> = [legacyShopAlias, ...(endpoint.middleware || [])];
 
 
     registry.register({
     registry.register({
       method: endpoint.method,
       method: endpoint.method,