From 2742d8a437c5af8661d9a7bd399b0450bac3f403 Mon Sep 17 00:00:00 2001 From: Myrotvorets Date: Tue, 24 Oct 2023 03:41:20 +0300 Subject: [PATCH] Use numberParamHandler --- src/controllers/search.mts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/controllers/search.mts b/src/controllers/search.mts index 6af1179d..382b9e34 100644 --- a/src/controllers/search.mts +++ b/src/controllers/search.mts @@ -1,6 +1,7 @@ -import { type NextFunction, type Request, type Response, Router } from 'express'; +import { type Request, type Response, Router } from 'express'; import type { SearchStats } from '@myrotvorets/facex'; import { asyncWrapperMiddleware } from '@myrotvorets/express-async-middleware-wrapper'; +import { numberParamHandler } from '@myrotvorets/express-microservice-middlewares'; import type { MatchedFace, RecoginizedFace } from '../services/search.mjs'; import { uploadErrorHandlerMiddleware } from '../middleware/upload.mjs'; import { faceXErrorHandlerMiddleware } from '../middleware/error.mjs'; @@ -93,23 +94,12 @@ async function matchedFacesHandler( res.json({ success: true, matches: result }); } -function intParamHandler( - req: Request>, - _res: Response, - next: NextFunction, - value: string, - name: string, -): void { - req.params[name] = +value; - next(); -} - export function searchController(): Router { const router = Router({ strict: true, caseSensitive: true }); - router.param('offset', intParamHandler); - router.param('count', intParamHandler); - router.param('faceid', intParamHandler); + router.param('offset', numberParamHandler); + router.param('count', numberParamHandler); + router.param('faceid', numberParamHandler); router.post('/search', asyncWrapperMiddleware(startSearchHandler)); router.get(`/search/:guid`, asyncWrapperMiddleware(statusHandler));