1 import 'express-validator'
2 import * as express from 'express'
4 import { SortType } from '../helpers'
5 import { database } from '../initializers'
7 function setPodsSort (req: express.Request, res: express.Response, next: express.NextFunction) {
8 if (!req.query.sort) req.query.sort = '-createdAt'
13 function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
14 if (!req.query.sort) req.query.sort = '-createdAt'
19 function setVideoAbusesSort (req: express.Request, res: express.Response, next: express.NextFunction) {
20 if (!req.query.sort) req.query.sort = '-createdAt'
25 function setVideoChannelsSort (req: express.Request, res: express.Response, next: express.NextFunction) {
26 if (!req.query.sort) req.query.sort = '-createdAt'
31 function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) {
32 if (!req.query.sort) req.query.sort = '-createdAt'
37 function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
38 let newSort: SortType = { sortModel: undefined, sortValue: undefined }
40 if (!req.query.sort) req.query.sort = '-createdAt'
42 // Set model we want to sort onto
43 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
44 req.query.sort === '-id' || req.query.sort === 'id') {
45 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
46 newSort.sortModel = undefined
48 newSort.sortModel = database.Video
51 newSort.sortValue = req.query.sort
53 req.query.sort = newSort
58 // ---------------------------------------------------------------------------