aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/sort.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/sort.ts')
-rw-r--r--server/middlewares/sort.ts27
1 files changed, 26 insertions, 1 deletions
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts
index 632b2fae4..687ce097b 100644
--- a/server/middlewares/sort.ts
+++ b/server/middlewares/sort.ts
@@ -1,6 +1,9 @@
1import 'express-validator' 1import 'express-validator'
2import * as express from 'express' 2import * as express from 'express'
3 3
4import { SortType } from '../helpers'
5import { database } from '../initializers'
6
4function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { 7function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
5 if (!req.query.sort) req.query.sort = '-createdAt' 8 if (!req.query.sort) req.query.sort = '-createdAt'
6 9
@@ -19,10 +22,32 @@ function setVideosSort (req: express.Request, res: express.Response, next: expre
19 return next() 22 return next()
20} 23}
21 24
25function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
26 let newSort: SortType = { sortModel: undefined, sortValue: undefined }
27
28 if (!req.query.sort) req.query.sort = '-createdAt'
29
30 // Set model we want to sort onto
31 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
32 req.query.sort === '-id' || req.query.sort === 'id') {
33 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
34 newSort.sortModel = undefined
35 } else {
36 newSort.sortModel = database.Video
37 }
38
39 newSort.sortValue = req.query.sort
40
41 req.query.sort = newSort
42
43 return next()
44}
45
22// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
23 47
24export { 48export {
25 setUsersSort, 49 setUsersSort,
26 setVideoAbusesSort, 50 setVideoAbusesSort,
27 setVideosSort 51 setVideosSort,
52 setBlacklistSort
28} 53}