diff options
Diffstat (limited to 'server/middlewares/validators/pagination.ts')
-rw-r--r-- | server/middlewares/validators/pagination.ts | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts index 1cae7848c..6b0a83d80 100644 --- a/server/middlewares/validators/pagination.ts +++ b/server/middlewares/validators/pagination.ts | |||
@@ -4,25 +4,30 @@ import { logger } from '../../helpers/logger' | |||
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { PAGINATION } from '@server/initializers/constants' | 5 | import { PAGINATION } from '@server/initializers/constants' |
6 | 6 | ||
7 | const paginationValidator = [ | 7 | const paginationValidator = paginationValidatorBuilder() |
8 | query('start') | ||
9 | .optional() | ||
10 | .isInt({ min: 0 }).withMessage('Should have a number start'), | ||
11 | query('count') | ||
12 | .optional() | ||
13 | .isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`), | ||
14 | 8 | ||
15 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 9 | function paginationValidatorBuilder (tags: string[] = []) { |
16 | logger.debug('Checking pagination parameters', { parameters: req.query }) | 10 | return [ |
11 | query('start') | ||
12 | .optional() | ||
13 | .isInt({ min: 0 }).withMessage('Should have a number start'), | ||
14 | query('count') | ||
15 | .optional() | ||
16 | .isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`), | ||
17 | 17 | ||
18 | if (areValidationErrors(req, res)) return | 18 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
19 | logger.debug('Checking pagination parameters', { parameters: req.query, tags }) | ||
19 | 20 | ||
20 | return next() | 21 | if (areValidationErrors(req, res)) return |
21 | } | 22 | |
22 | ] | 23 | return next() |
24 | } | ||
25 | ] | ||
26 | } | ||
23 | 27 | ||
24 | // --------------------------------------------------------------------------- | 28 | // --------------------------------------------------------------------------- |
25 | 29 | ||
26 | export { | 30 | export { |
27 | paginationValidator | 31 | paginationValidator, |
32 | paginationValidatorBuilder | ||
28 | } | 33 | } |