]>
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 | ||
8a02bd04 C |
7 | function setPodsSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
8 | if (!req.query.sort) req.query.sort = '-createdAt' | |
9 | ||
10 | return next() | |
11 | } | |
12 | ||
69818c93 | 13 | function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
feb4bdfd | 14 | if (!req.query.sort) req.query.sort = '-createdAt' |
5c39adb7 C |
15 | |
16 | return next() | |
17 | } | |
18 | ||
69818c93 | 19 | function setVideoAbusesSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
55fa55a9 C |
20 | if (!req.query.sort) req.query.sort = '-createdAt' |
21 | ||
22 | return next() | |
23 | } | |
24 | ||
69818c93 | 25 | function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
feb4bdfd | 26 | if (!req.query.sort) req.query.sort = '-createdAt' |
a877d5ac C |
27 | |
28 | return next() | |
29 | } | |
30 | ||
792dbaf0 GS |
31 | function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
32 | let newSort: SortType = { sortModel: undefined, sortValue: undefined } | |
33 | ||
34 | if (!req.query.sort) req.query.sort = '-createdAt' | |
35 | ||
36 | // Set model we want to sort onto | |
37 | if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' || | |
38 | req.query.sort === '-id' || req.query.sort === 'id') { | |
39 | // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ... | |
40 | newSort.sortModel = undefined | |
41 | } else { | |
42 | newSort.sortModel = database.Video | |
43 | } | |
44 | ||
45 | newSort.sortValue = req.query.sort | |
46 | ||
47 | req.query.sort = newSort | |
48 | ||
49 | return next() | |
50 | } | |
51 | ||
a877d5ac C |
52 | // --------------------------------------------------------------------------- |
53 | ||
65fcc311 | 54 | export { |
8a02bd04 | 55 | setPodsSort, |
65fcc311 C |
56 | setUsersSort, |
57 | setVideoAbusesSort, | |
792dbaf0 GS |
58 | setVideosSort, |
59 | setBlacklistSort | |
65fcc311 | 60 | } |