1 import 'express-validator'
2 import * as express from 'express'
4 import { SortType } from '../helpers'
5 import { database } from '../initializers'
7 function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
8 if (!req.query.sort) req.query.sort = '-createdAt'
13 function setVideoAbusesSort (req: express.Request, res: express.Response, next: express.NextFunction) {
14 if (!req.query.sort) req.query.sort = '-createdAt'
19 function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) {
20 if (!req.query.sort) req.query.sort = '-createdAt'
25 function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
26 let newSort: SortType = { sortModel: undefined, sortValue: undefined }
28 if (!req.query.sort) req.query.sort = '-createdAt'
30 // Set model we want to sort onto
31 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
32 req.query.sort === '-id' || req.query.sort === 'id') {
33 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
34 newSort.sortModel = undefined
36 newSort.sortModel = database.Video
39 newSort.sortValue = req.query.sort
41 req.query.sort = newSort
46 // ---------------------------------------------------------------------------