]>
Commit | Line | Data |
---|---|---|
a877d5ac C |
1 | 'use strict' |
2 | ||
3 | const checkErrors = require('./utils').checkErrors | |
4 | const constants = require('../../initializers/constants') | |
5 | const logger = require('../../helpers/logger') | |
6 | ||
fc51fde0 | 7 | const validatorsSort = { |
c4403b29 | 8 | usersSort, |
55fa55a9 | 9 | videoAbusesSort, |
c4403b29 | 10 | videosSort |
a877d5ac C |
11 | } |
12 | ||
5c39adb7 C |
13 | function usersSort (req, res, next) { |
14 | const sortableColumns = constants.SORTABLE_COLUMNS.USERS | |
15 | ||
55fa55a9 C |
16 | checkSort(req, res, next, sortableColumns) |
17 | } | |
5c39adb7 | 18 | |
55fa55a9 C |
19 | function videoAbusesSort (req, res, next) { |
20 | const sortableColumns = constants.SORTABLE_COLUMNS.VIDEO_ABUSES | |
5c39adb7 | 21 | |
55fa55a9 | 22 | checkSort(req, res, next, sortableColumns) |
5c39adb7 C |
23 | } |
24 | ||
a877d5ac C |
25 | function videosSort (req, res, next) { |
26 | const sortableColumns = constants.SORTABLE_COLUMNS.VIDEOS | |
27 | ||
55fa55a9 C |
28 | checkSort(req, res, next, sortableColumns) |
29 | } | |
30 | ||
31 | // --------------------------------------------------------------------------- | |
32 | ||
33 | module.exports = validatorsSort | |
34 | ||
35 | // --------------------------------------------------------------------------- | |
36 | ||
37 | function checkSort (req, res, next, sortableColumns) { | |
a877d5ac C |
38 | req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns) |
39 | ||
40 | logger.debug('Checking sort parameters', { parameters: req.query }) | |
41 | ||
42 | checkErrors(req, res, next) | |
43 | } |