]>
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 | 4 | import { areValidationErrors } from './shared' |
fbf1134e | 5 | |
18b24b2d | 6 | const paginationValidator = paginationValidatorBuilder() |
fbf1134e | 7 | |
18b24b2d C |
8 | function paginationValidatorBuilder (tags: string[] = []) { |
9 | return [ | |
10 | query('start') | |
11 | .optional() | |
396f6f01 | 12 | .isInt({ min: 0 }), |
18b24b2d C |
13 | query('count') |
14 | .optional() | |
15 | .isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`), | |
fbf1134e | 16 | |
18b24b2d | 17 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
a85d5303 | 18 | if (areValidationErrors(req, res, { tags })) return |
18b24b2d C |
19 | |
20 | return next() | |
21 | } | |
22 | ] | |
23 | } | |
fbf1134e C |
24 | |
25 | // --------------------------------------------------------------------------- | |
26 | ||
65fcc311 | 27 | export { |
18b24b2d C |
28 | paginationValidator, |
29 | paginationValidatorBuilder | |
65fcc311 | 30 | } |