2017-06-10 16:15:25 -04:00
|
|
|
import * as express from 'express'
|
2019-07-25 10:23:44 -04:00
|
|
|
import { query } from 'express-validator'
|
2017-12-28 05:16:08 -05:00
|
|
|
import { logger } from '../../helpers/logger'
|
2017-11-27 11:30:46 -05:00
|
|
|
import { areValidationErrors } from './utils'
|
2020-01-09 03:36:31 -05:00
|
|
|
import { PAGINATION } from '@server/initializers/constants'
|
2016-05-13 12:10:46 -04:00
|
|
|
|
2017-09-15 06:17:08 -04:00
|
|
|
const paginationValidator = [
|
2020-01-09 03:36:31 -05:00
|
|
|
query('start')
|
|
|
|
.optional()
|
|
|
|
.isInt({ min: 0 }).withMessage('Should have a number start'),
|
|
|
|
query('count')
|
|
|
|
.optional()
|
|
|
|
.isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`),
|
2016-05-13 12:10:46 -04:00
|
|
|
|
2017-09-15 06:17:08 -04:00
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking pagination parameters', { parameters: req.query })
|
2016-05-13 12:10:46 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
}
|
|
|
|
]
|
2016-05-13 12:10:46 -04:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 16:22:03 -04:00
|
|
|
export {
|
|
|
|
paginationValidator
|
|
|
|
}
|