]>
Commit | Line | Data |
---|---|---|
69818c93 | 1 | import * as express from 'express' |
c8861d5d | 2 | import { query } from 'express-validator' |
da854ddd | 3 | import { logger } from '../../helpers/logger' |
a2431b7d | 4 | import { areValidationErrors } from './utils' |
e0b56b74 | 5 | import { PAGINATION } from '@server/initializers/constants' |
fbf1134e | 6 | |
b60e5f38 | 7 | const paginationValidator = [ |
e0b56b74 C |
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})`), | |
fbf1134e | 14 | |
b60e5f38 C |
15 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
16 | logger.debug('Checking pagination parameters', { parameters: req.query }) | |
fbf1134e | 17 | |
a2431b7d C |
18 | if (areValidationErrors(req, res)) return |
19 | ||
20 | return next() | |
b60e5f38 C |
21 | } |
22 | ] | |
fbf1134e C |
23 | |
24 | // --------------------------------------------------------------------------- | |
25 | ||
65fcc311 C |
26 | export { |
27 | paginationValidator | |
28 | } |