diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-16 22:31:45 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-16 22:31:45 +0200 |
commit | 5c39adb7313e0696aabb4b71196ab7b0b378c359 (patch) | |
tree | ac44b67890509338b984f8cbf11660dc77cdd0fd /server/middlewares | |
parent | 089ff2f2046fdbaf9531726eea1f8c6726ebf0c0 (diff) | |
download | PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.tar.gz PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.tar.zst PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.zip |
Server: add user list sort/pagination
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/sort.js | 7 | ||||
-rw-r--r-- | server/middlewares/validators/sort.js | 11 |
2 files changed, 18 insertions, 0 deletions
diff --git a/server/middlewares/sort.js b/server/middlewares/sort.js index 9f52290a6..8ed157805 100644 --- a/server/middlewares/sort.js +++ b/server/middlewares/sort.js | |||
@@ -1,9 +1,16 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const sortMiddleware = { | 3 | const sortMiddleware = { |
4 | setUsersSort: setUsersSort, | ||
4 | setVideosSort: setVideosSort | 5 | setVideosSort: setVideosSort |
5 | } | 6 | } |
6 | 7 | ||
8 | function setUsersSort (req, res, next) { | ||
9 | if (!req.query.sort) req.query.sort = '-createdDate' | ||
10 | |||
11 | return next() | ||
12 | } | ||
13 | |||
7 | function setVideosSort (req, res, next) { | 14 | function setVideosSort (req, res, next) { |
8 | if (!req.query.sort) req.query.sort = '-createdDate' | 15 | if (!req.query.sort) req.query.sort = '-createdDate' |
9 | 16 | ||
diff --git a/server/middlewares/validators/sort.js b/server/middlewares/validators/sort.js index 56b63cc8b..37b34ef52 100644 --- a/server/middlewares/validators/sort.js +++ b/server/middlewares/validators/sort.js | |||
@@ -5,9 +5,20 @@ const constants = require('../../initializers/constants') | |||
5 | const logger = require('../../helpers/logger') | 5 | const logger = require('../../helpers/logger') |
6 | 6 | ||
7 | const validatorsSort = { | 7 | const validatorsSort = { |
8 | usersSort: usersSort, | ||
8 | videosSort: videosSort | 9 | videosSort: videosSort |
9 | } | 10 | } |
10 | 11 | ||
12 | function usersSort (req, res, next) { | ||
13 | const sortableColumns = constants.SORTABLE_COLUMNS.USERS | ||
14 | |||
15 | req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns) | ||
16 | |||
17 | logger.debug('Checking sort parameters', { parameters: req.query }) | ||
18 | |||
19 | checkErrors(req, res, next) | ||
20 | } | ||
21 | |||
11 | function videosSort (req, res, next) { | 22 | function videosSort (req, res, next) { |
12 | const sortableColumns = constants.SORTABLE_COLUMNS.VIDEOS | 23 | const sortableColumns = constants.SORTABLE_COLUMNS.VIDEOS |
13 | 24 | ||