aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/pagination.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-03-09 09:22:05 +0100
committerChocobozzz <me@florianbigard.com>2021-03-24 18:18:40 +0100
commit18b24b2dc5a21007f62b2e625d50b1f4b7dec784 (patch)
tree11327be380e5fef0795358b189be68aa5d78924b /server/middlewares/validators/pagination.ts
parentdb4b15f21fbf4e33434e930ffc7fb768cdcf9d42 (diff)
downloadPeerTube-18b24b2dc5a21007f62b2e625d50b1f4b7dec784.tar.gz
PeerTube-18b24b2dc5a21007f62b2e625d50b1f4b7dec784.tar.zst
PeerTube-18b24b2dc5a21007f62b2e625d50b1f4b7dec784.zip
Add jobs tag to logger
Diffstat (limited to 'server/middlewares/validators/pagination.ts')
-rw-r--r--server/middlewares/validators/pagination.ts33
1 files changed, 19 insertions, 14 deletions
diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts
index 1cae7848c..6b0a83d80 100644
--- a/server/middlewares/validators/pagination.ts
+++ b/server/middlewares/validators/pagination.ts
@@ -4,25 +4,30 @@ import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5import { PAGINATION } from '@server/initializers/constants' 5import { PAGINATION } from '@server/initializers/constants'
6 6
7const paginationValidator = [ 7const paginationValidator = paginationValidatorBuilder()
8 query('start')
9 .optional()
10 .isInt({ min: 0 }).withMessage('Should have a number start'),
11 query('count')
12 .optional()
13 .isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`),
14 8
15 (req: express.Request, res: express.Response, next: express.NextFunction) => { 9function paginationValidatorBuilder (tags: string[] = []) {
16 logger.debug('Checking pagination parameters', { parameters: req.query }) 10 return [
11 query('start')
12 .optional()
13 .isInt({ min: 0 }).withMessage('Should have a number start'),
14 query('count')
15 .optional()
16 .isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`),
17 17
18 if (areValidationErrors(req, res)) return 18 (req: express.Request, res: express.Response, next: express.NextFunction) => {
19 logger.debug('Checking pagination parameters', { parameters: req.query, tags })
19 20
20 return next() 21 if (areValidationErrors(req, res)) return
21 } 22
22] 23 return next()
24 }
25 ]
26}
23 27
24// --------------------------------------------------------------------------- 28// ---------------------------------------------------------------------------
25 29
26export { 30export {
27 paginationValidator 31 paginationValidator,
32 paginationValidatorBuilder
28} 33}