diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-02-26 19:26:57 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-02-26 20:01:26 +0100 |
commit | 9c2c18f3ab2cf18aeb1eb38da48f0ba553f5d9be (patch) | |
tree | 53fb76d0be4224f7af9d0379cfb43f91cf3ddb6e /server/middlewares/validators | |
parent | e4c87ec26962e359d1c70b03ed188a3f19d6a25b (diff) | |
download | PeerTube-9c2c18f3ab2cf18aeb1eb38da48f0ba553f5d9be.tar.gz PeerTube-9c2c18f3ab2cf18aeb1eb38da48f0ba553f5d9be.tar.zst PeerTube-9c2c18f3ab2cf18aeb1eb38da48f0ba553f5d9be.zip |
Server: little sort refractoring
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/sort.js | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/server/middlewares/validators/sort.js b/server/middlewares/validators/sort.js index b7eec0316..017d266e6 100644 --- a/server/middlewares/validators/sort.js +++ b/server/middlewares/validators/sort.js | |||
@@ -10,22 +10,21 @@ const validatorsSort = { | |||
10 | videosSort | 10 | videosSort |
11 | } | 11 | } |
12 | 12 | ||
13 | function usersSort (req, res, next) { | 13 | // Initialize constants here for better performances |
14 | const sortableColumns = constants.SORTABLE_COLUMNS.USERS | 14 | const SORTABLE_USERS_COLUMNS = createSortableColumns(constants.SORTABLE_COLUMNS.USERS) |
15 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(constants.SORTABLE_COLUMNS.VIDEO_ABUSES) | ||
16 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(constants.SORTABLE_COLUMNS.VIDEOS) | ||
15 | 17 | ||
16 | checkSort(req, res, next, sortableColumns) | 18 | function usersSort (req, res, next) { |
19 | checkSort(req, res, next, SORTABLE_USERS_COLUMNS) | ||
17 | } | 20 | } |
18 | 21 | ||
19 | function videoAbusesSort (req, res, next) { | 22 | function videoAbusesSort (req, res, next) { |
20 | const sortableColumns = constants.SORTABLE_COLUMNS.VIDEO_ABUSES | 23 | checkSort(req, res, next, SORTABLE_VIDEO_ABUSES_COLUMNS) |
21 | |||
22 | checkSort(req, res, next, sortableColumns) | ||
23 | } | 24 | } |
24 | 25 | ||
25 | function videosSort (req, res, next) { | 26 | function videosSort (req, res, next) { |
26 | const sortableColumns = constants.SORTABLE_COLUMNS.VIDEOS | 27 | checkSort(req, res, next, SORTABLE_VIDEOS_COLUMNS) |
27 | |||
28 | checkSort(req, res, next, sortableColumns) | ||
29 | } | 28 | } |
30 | 29 | ||
31 | // --------------------------------------------------------------------------- | 30 | // --------------------------------------------------------------------------- |
@@ -41,3 +40,9 @@ function checkSort (req, res, next, sortableColumns) { | |||
41 | 40 | ||
42 | checkErrors(req, res, next) | 41 | checkErrors(req, res, next) |
43 | } | 42 | } |
43 | |||
44 | function createSortableColumns (sortableColumns) { | ||
45 | const sortableColumnDesc = sortableColumns.map(sortableColumn => '-' + sortableColumn) | ||
46 | |||
47 | return sortableColumns.concat(sortableColumnDesc) | ||
48 | } | ||