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