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