1 import * as express from 'express'
2 import 'express-validator'
3 import { SortType } from '../models/utils'
5 function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {
6 if (!req.query.sort) req.query.sort = '-createdAt'
11 function setDefaultSearchSort (req: express.Request, res: express.Response, next: express.NextFunction) {
12 if (!req.query.sort) req.query.sort = '-match'
17 function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
18 let newSort: SortType = { sortModel: undefined, sortValue: '' }
20 if (!req.query.sort) req.query.sort = '-createdAt'
22 // Set model we want to sort onto
23 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
24 req.query.sort === '-id' || req.query.sort === 'id') {
25 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
26 newSort.sortModel = undefined
28 newSort.sortModel = 'Video'
31 newSort.sortValue = req.query.sort
33 req.query.sort = newSort
38 // ---------------------------------------------------------------------------