]>
Commit | Line | Data |
---|---|---|
69818c93 C |
1 | import 'express-validator' |
2 | import * as express from 'express' | |
3 | ||
792dbaf0 GS |
4 | import { SortType } from '../helpers' |
5 | import { database } from '../initializers' | |
6 | ||
69818c93 | 7 | function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
feb4bdfd | 8 | if (!req.query.sort) req.query.sort = '-createdAt' |
5c39adb7 C |
9 | |
10 | return next() | |
11 | } | |
12 | ||
69818c93 | 13 | function setVideoAbusesSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
55fa55a9 C |
14 | if (!req.query.sort) req.query.sort = '-createdAt' |
15 | ||
16 | return next() | |
17 | } | |
18 | ||
69818c93 | 19 | function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
feb4bdfd | 20 | if (!req.query.sort) req.query.sort = '-createdAt' |
a877d5ac C |
21 | |
22 | return next() | |
23 | } | |
24 | ||
792dbaf0 GS |
25 | function 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 | ||
a877d5ac C |
46 | // --------------------------------------------------------------------------- |
47 | ||
65fcc311 C |
48 | export { |
49 | setUsersSort, | |
50 | setVideoAbusesSort, | |
792dbaf0 GS |
51 | setVideosSort, |
52 | setBlacklistSort | |
65fcc311 | 53 | } |