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