]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/sort.ts
Add pod list endpoint with pagination, sort...
[github/Chocobozzz/PeerTube.git] / server / middlewares / sort.ts
CommitLineData
69818c93
C
1import 'express-validator'
2import * as express from 'express'
3
792dbaf0
GS
4import { SortType } from '../helpers'
5import { database } from '../initializers'
6
8a02bd04
C
7function setPodsSort (req: express.Request, res: express.Response, next: express.NextFunction) {
8 if (!req.query.sort) req.query.sort = '-createdAt'
9
10 return next()
11}
12
69818c93 13function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
feb4bdfd 14 if (!req.query.sort) req.query.sort = '-createdAt'
5c39adb7
C
15
16 return next()
17}
18
69818c93 19function setVideoAbusesSort (req: express.Request, res: express.Response, next: express.NextFunction) {
55fa55a9
C
20 if (!req.query.sort) req.query.sort = '-createdAt'
21
22 return next()
23}
24
69818c93 25function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) {
feb4bdfd 26 if (!req.query.sort) req.query.sort = '-createdAt'
a877d5ac
C
27
28 return next()
29}
30
792dbaf0
GS
31function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
32 let newSort: SortType = { sortModel: undefined, sortValue: undefined }
33
34 if (!req.query.sort) req.query.sort = '-createdAt'
35
36 // Set model we want to sort onto
37 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
38 req.query.sort === '-id' || req.query.sort === 'id') {
39 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
40 newSort.sortModel = undefined
41 } else {
42 newSort.sortModel = database.Video
43 }
44
45 newSort.sortValue = req.query.sort
46
47 req.query.sort = newSort
48
49 return next()
50}
51
a877d5ac
C
52// ---------------------------------------------------------------------------
53
65fcc311 54export {
8a02bd04 55 setPodsSort,
65fcc311
C
56 setUsersSort,
57 setVideoAbusesSort,
792dbaf0
GS
58 setVideosSort,
59 setBlacklistSort
65fcc311 60}