]>
Commit | Line | Data |
---|---|---|
69818c93 | 1 | import * as express from 'express' |
3fd3ab2d | 2 | import 'express-validator' |
06215f15 | 3 | import { SortType } from '../models/utils' |
792dbaf0 | 4 | |
1174a847 | 5 | function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
7a7724e6 C |
6 | if (!req.query.sort) req.query.sort = '-createdAt' |
7 | ||
8 | return next() | |
9 | } | |
10 | ||
57c36b27 | 11 | function setDefaultSearchSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
d525fc39 | 12 | if (!req.query.sort) req.query.sort = '-match' |
57c36b27 C |
13 | |
14 | return next() | |
15 | } | |
16 | ||
792dbaf0 | 17 | function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
c1e791ba | 18 | let newSort: SortType = { sortModel: undefined, sortValue: '' } |
792dbaf0 GS |
19 | |
20 | if (!req.query.sort) req.query.sort = '-createdAt' | |
21 | ||
22 | // Set model we want to sort onto | |
23 | if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' || | |
24 | req.query.sort === '-id' || req.query.sort === 'id') { | |
25 | // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ... | |
26 | newSort.sortModel = undefined | |
27 | } else { | |
3fd3ab2d | 28 | newSort.sortModel = 'Video' |
792dbaf0 GS |
29 | } |
30 | ||
31 | newSort.sortValue = req.query.sort | |
32 | ||
33 | req.query.sort = newSort | |
34 | ||
35 | return next() | |
36 | } | |
37 | ||
a877d5ac C |
38 | // --------------------------------------------------------------------------- |
39 | ||
65fcc311 | 40 | export { |
1174a847 | 41 | setDefaultSort, |
57c36b27 | 42 | setDefaultSearchSort, |
1174a847 | 43 | setBlacklistSort |
65fcc311 | 44 | } |