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