]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/sort.ts
Speed up populate database script
[github/Chocobozzz/PeerTube.git] / server / middlewares / sort.ts
CommitLineData
69818c93 1import * as express from 'express'
3fd3ab2d 2import 'express-validator'
da854ddd 3import { SortType } from '../helpers/utils'
792dbaf0 4
1174a847 5function 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
792dbaf0
GS
11function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
12 let newSort: SortType = { sortModel: undefined, sortValue: undefined }
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 {
3fd3ab2d 22 newSort.sortModel = 'Video'
792dbaf0
GS
23 }
24
25 newSort.sortValue = req.query.sort
26
27 req.query.sort = newSort
28
29 return next()
30}
31
a877d5ac
C
32// ---------------------------------------------------------------------------
33
65fcc311 34export {
1174a847
C
35 setDefaultSort,
36 setBlacklistSort
65fcc311 37}