2022-06-03 10:54:30 +02:00
|
|
|
import express from 'express'
|
2020-05-29 09:13:22 +02:00
|
|
|
import { check } from 'express-validator'
|
2021-08-02 16:16:27 +02:00
|
|
|
import { PAGINATION_COUNT, PAGINATION_START } from '../../initializers/constants'
|
2020-02-13 11:49:03 +01:00
|
|
|
import { areValidationErrors } from './utils'
|
|
|
|
|
|
|
|
const paginationValidator = [
|
2021-08-02 15:54:29 +02:00
|
|
|
check('start')
|
|
|
|
.optional()
|
2021-08-02 16:17:44 +02:00
|
|
|
.isInt({ min: 0, max: PAGINATION_START.MAX }).withMessage(`Should have a number start (>= 0 and < ${PAGINATION_START.MAX})`),
|
2021-08-02 15:54:29 +02:00
|
|
|
|
|
|
|
check('count')
|
|
|
|
.optional()
|
2021-08-02 16:17:44 +02:00
|
|
|
.isInt({ min: 0, max: PAGINATION_COUNT.MAX }).withMessage(`Should have a number count (> 0 and < ${PAGINATION_COUNT.MAX})`),
|
2020-02-13 11:49:03 +01:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
paginationValidator
|
|
|
|
}
|