]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/pagination.ts
add user account email verificiation (#977)
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / pagination.ts
index cca8295ffddc731bc309c3e189fb58210b9fffb0..e1ed8cd65cb6979c7c85fdb1aee46f1b6cceec01 100644 (file)
@@ -1,17 +1,20 @@
-import 'express-validator'
 import * as express from 'express'
+import { query } from 'express-validator/check'
+import { logger } from '../../helpers/logger'
+import { areValidationErrors } from './utils'
 
-import { checkErrors } from './utils'
-import { logger } from '../../helpers'
+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'),
 
-function paginationValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
-  req.checkQuery('start', 'Should have a number start').optional().isInt()
-  req.checkQuery('count', 'Should have a number count').optional().isInt()
+  (req: express.Request, res: express.Response, next: express.NextFunction) => {
+    logger.debug('Checking pagination parameters', { parameters: req.query })
 
-  logger.debug('Checking pagination parameters', { parameters: req.query })
+    if (areValidationErrors(req, res)) return
 
-  checkErrors(req, res, next)
-}
+    return next()
+  }
+]
 
 // ---------------------------------------------------------------------------