]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/pagination.ts
Add quota used in users list
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / pagination.ts
index de719c05bc42fd7f80c2a414332205c535655e5d..e1ed8cd65cb6979c7c85fdb1aee46f1b6cceec01 100644 (file)
@@ -1,14 +1,20 @@
-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()
+  }
+]
 
 // ---------------------------------------------------------------------------