diff options
Diffstat (limited to 'server/middlewares/reqValidators')
-rw-r--r-- | server/middlewares/reqValidators/index.js | 2 | ||||
-rw-r--r-- | server/middlewares/reqValidators/pagination.js | 6 | ||||
-rw-r--r-- | server/middlewares/reqValidators/sort.js | 23 |
3 files changed, 28 insertions, 3 deletions
diff --git a/server/middlewares/reqValidators/index.js b/server/middlewares/reqValidators/index.js index b732a27b6..be68f6a29 100644 --- a/server/middlewares/reqValidators/index.js +++ b/server/middlewares/reqValidators/index.js | |||
@@ -3,12 +3,14 @@ | |||
3 | const paginationReqValidators = require('./pagination') | 3 | const paginationReqValidators = require('./pagination') |
4 | const podsReqValidators = require('./pods') | 4 | const podsReqValidators = require('./pods') |
5 | const remoteReqValidators = require('./remote') | 5 | const remoteReqValidators = require('./remote') |
6 | const sortReqValidators = require('./sort') | ||
6 | const videosReqValidators = require('./videos') | 7 | const videosReqValidators = require('./videos') |
7 | 8 | ||
8 | const reqValidators = { | 9 | const reqValidators = { |
9 | pagination: paginationReqValidators, | 10 | pagination: paginationReqValidators, |
10 | pods: podsReqValidators, | 11 | pods: podsReqValidators, |
11 | remote: remoteReqValidators, | 12 | remote: remoteReqValidators, |
13 | sort: sortReqValidators, | ||
12 | videos: videosReqValidators | 14 | videos: videosReqValidators |
13 | } | 15 | } |
14 | 16 | ||
diff --git a/server/middlewares/reqValidators/pagination.js b/server/middlewares/reqValidators/pagination.js index ca8375396..e598f269a 100644 --- a/server/middlewares/reqValidators/pagination.js +++ b/server/middlewares/reqValidators/pagination.js | |||
@@ -8,10 +8,10 @@ const reqValidatorsPagination = { | |||
8 | } | 8 | } |
9 | 9 | ||
10 | function pagination (req, res, next) { | 10 | function pagination (req, res, next) { |
11 | req.checkParams('start', 'Should have a number start').optional().isInt() | 11 | req.checkQuery('start', 'Should have a number start').optional().isInt() |
12 | req.checkParams('count', 'Should have a number count').optional().isInt() | 12 | req.checkQuery('count', 'Should have a number count').optional().isInt() |
13 | 13 | ||
14 | logger.debug('Checking pagination parameters', { parameters: req.params }) | 14 | logger.debug('Checking pagination parameters', { parameters: req.query }) |
15 | 15 | ||
16 | checkErrors(req, res, next) | 16 | checkErrors(req, res, next) |
17 | } | 17 | } |
diff --git a/server/middlewares/reqValidators/sort.js b/server/middlewares/reqValidators/sort.js new file mode 100644 index 000000000..06e680ef4 --- /dev/null +++ b/server/middlewares/reqValidators/sort.js | |||
@@ -0,0 +1,23 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const checkErrors = require('./utils').checkErrors | ||
4 | const constants = require('../../initializers/constants') | ||
5 | const logger = require('../../helpers/logger') | ||
6 | |||
7 | const reqValidatorsSort = { | ||
8 | videosSort: videosSort | ||
9 | } | ||
10 | |||
11 | function videosSort (req, res, next) { | ||
12 | const sortableColumns = constants.SORTABLE_COLUMNS.VIDEOS | ||
13 | |||
14 | req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns) | ||
15 | |||
16 | logger.debug('Checking sort parameters', { parameters: req.query }) | ||
17 | |||
18 | checkErrors(req, res, next) | ||
19 | } | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | module.exports = reqValidatorsSort | ||