diff options
author | Chocobozzz <me@florianbigard.com> | 2023-01-10 11:09:30 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-01-10 11:56:08 +0100 |
commit | 8c4bbd946d2247c2e239cbbf8773d2d31c1a57aa (patch) | |
tree | 4e7d3711cccb095d4356c59554bdfd4e16502832 /server/middlewares | |
parent | a8749f7c3b137f433e6944bb99fd721a6f0cfc1e (diff) | |
download | PeerTube-8c4bbd946d2247c2e239cbbf8773d2d31c1a57aa.tar.gz PeerTube-8c4bbd946d2247c2e239cbbf8773d2d31c1a57aa.tar.zst PeerTube-8c4bbd946d2247c2e239cbbf8773d2d31c1a57aa.zip |
Refactor model utils
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/sort.ts | 23 |
1 files changed, 1 insertions, 22 deletions
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts index 458895898..77a532276 100644 --- a/server/middlewares/sort.ts +++ b/server/middlewares/sort.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { SortType } from '../models/utils' | ||
3 | 2 | ||
4 | const setDefaultSort = setDefaultSortFactory('-createdAt') | 3 | const setDefaultSort = setDefaultSortFactory('-createdAt') |
5 | const setDefaultVideosSort = setDefaultSortFactory('-publishedAt') | 4 | const setDefaultVideosSort = setDefaultSortFactory('-publishedAt') |
@@ -7,27 +6,7 @@ const setDefaultVideosSort = setDefaultSortFactory('-publishedAt') | |||
7 | const setDefaultVideoRedundanciesSort = setDefaultSortFactory('name') | 6 | const setDefaultVideoRedundanciesSort = setDefaultSortFactory('name') |
8 | 7 | ||
9 | const setDefaultSearchSort = setDefaultSortFactory('-match') | 8 | const setDefaultSearchSort = setDefaultSortFactory('-match') |
10 | 9 | const setBlacklistSort = setDefaultSortFactory('-createdAt') | |
11 | function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
12 | const newSort: SortType = { sortModel: undefined, sortValue: '' } | ||
13 | |||
14 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
15 | |||
16 | // Set model we want to sort onto | ||
17 | if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' || | ||
18 | req.query.sort === '-id' || req.query.sort === 'id') { | ||
19 | // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter... | ||
20 | newSort.sortModel = undefined | ||
21 | } else { | ||
22 | newSort.sortModel = 'Video' | ||
23 | } | ||
24 | |||
25 | newSort.sortValue = req.query.sort | ||
26 | |||
27 | req.query.sort = newSort | ||
28 | |||
29 | return next() | ||
30 | } | ||
31 | 10 | ||
32 | // --------------------------------------------------------------------------- | 11 | // --------------------------------------------------------------------------- |
33 | 12 | ||