]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
c8861d5d | 2 | import { query } from 'express-validator' |
e0b56b74 | 3 | import { PAGINATION } from '@server/initializers/constants' |
10363c74 C |
4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './shared' | |
fbf1134e | 6 | |
18b24b2d | 7 | const paginationValidator = paginationValidatorBuilder() |
fbf1134e | 8 | |
18b24b2d C |
9 | function paginationValidatorBuilder (tags: string[] = []) { |
10 | return [ | |
11 | query('start') | |
12 | .optional() | |
396f6f01 | 13 | .isInt({ min: 0 }), |
18b24b2d C |
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})`), | |
fbf1134e | 17 | |
18b24b2d C |
18 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
19 | logger.debug('Checking pagination parameters', { parameters: req.query, tags }) | |
a2431b7d | 20 | |
18b24b2d C |
21 | if (areValidationErrors(req, res)) return |
22 | ||
23 | return next() | |
24 | } | |
25 | ] | |
26 | } | |
fbf1134e C |
27 | |
28 | // --------------------------------------------------------------------------- | |
29 | ||
65fcc311 | 30 | export { |
18b24b2d C |
31 | paginationValidator, |
32 | paginationValidatorBuilder | |
65fcc311 | 33 | } |