-import { checkErrors } from './utils'
-import { logger } from '../../helpers'
+import * as express from 'express'
+import { query } from 'express-validator/check'
+import { logger } from '../../helpers/logger'
+import { areValidationErrors } from './utils'
-function paginationValidator (req, res, next) {
- req.checkQuery('start', 'Should have a number start').optional().isInt()
- req.checkQuery('count', 'Should have a number count').optional().isInt()
+const paginationValidator = [
+ query('start').optional().isInt({ min: 0 }).withMessage('Should have a number start'),
+ query('count').optional().isInt({ min: 0 }).withMessage('Should have a number count'),
- logger.debug('Checking pagination parameters', { parameters: req.query })
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking pagination parameters', { parameters: req.query })
- checkErrors(req, res, next)
-}
+ if (areValidationErrors(req, res)) return
+
+ return next()
+ }
+]
// ---------------------------------------------------------------------------