pagination.ts 730 B

1234567891011121314151617181920212223
  1. import * as express from 'express'
  2. import { query } from 'express-validator/check'
  3. import { logger } from '../../helpers/logger'
  4. import { areValidationErrors } from './utils'
  5. const paginationValidator = [
  6. query('start').optional().isInt({ min: 0 }).withMessage('Should have a number start'),
  7. query('count').optional().isInt({ min: 0 }).withMessage('Should have a number count'),
  8. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  9. logger.debug('Checking pagination parameters', { parameters: req.query })
  10. if (areValidationErrors(req, res)) return
  11. return next()
  12. }
  13. ]
  14. // ---------------------------------------------------------------------------
  15. export {
  16. paginationValidator
  17. }