2016-05-17 21:03:00 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const checkErrors = require('./utils').checkErrors
|
|
|
|
const constants = require('../../initializers/constants')
|
|
|
|
const logger = require('../../helpers/logger')
|
|
|
|
|
2016-07-01 16:16:40 +02:00
|
|
|
const validatorsSort = {
|
2016-10-02 12:19:02 +02:00
|
|
|
usersSort,
|
|
|
|
videosSort
|
2016-05-17 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2016-08-16 22:31:45 +02:00
|
|
|
function usersSort (req, res, next) {
|
|
|
|
const sortableColumns = constants.SORTABLE_COLUMNS.USERS
|
|
|
|
|
|
|
|
req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns)
|
|
|
|
|
|
|
|
logger.debug('Checking sort parameters', { parameters: req.query })
|
|
|
|
|
|
|
|
checkErrors(req, res, next)
|
|
|
|
}
|
|
|
|
|
2016-05-17 21:03:00 +02:00
|
|
|
function videosSort (req, res, next) {
|
|
|
|
const sortableColumns = constants.SORTABLE_COLUMNS.VIDEOS
|
|
|
|
|
|
|
|
req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns)
|
|
|
|
|
|
|
|
logger.debug('Checking sort parameters', { parameters: req.query })
|
|
|
|
|
|
|
|
checkErrors(req, res, next)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 16:16:40 +02:00
|
|
|
module.exports = validatorsSort
|