PeerTube/server/middlewares/validators/pagination.ts

24 lines
730 B
TypeScript
Raw Normal View History

2017-06-10 23:15:25 +03:00
import * as express from 'express'
2017-11-27 19:30:46 +03:00
import { query } from 'express-validator/check'
2017-12-28 13:16:08 +03:00
import { logger } from '../../helpers/logger'
2017-11-27 19:30:46 +03:00
import { areValidationErrors } from './utils'
2017-09-15 13:17:08 +03:00
const paginationValidator = [
2017-12-27 18:11:53 +03: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'),
2017-09-15 13:17:08 +03:00
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking pagination parameters', { parameters: req.query })
2017-11-27 19:30:46 +03:00
if (areValidationErrors(req, res)) return
return next()
2017-09-15 13:17:08 +03:00
}
]
// ---------------------------------------------------------------------------
2017-05-15 23:22:03 +03:00
export {
paginationValidator
}