1 import * as express from 'express'
2 import 'express-validator'
3 import { SortType } from '../helpers/utils'
5 function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {
6 if (!req.query.sort) req.query.sort = '-createdAt'
11 function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
12 let newSort: SortType = { sortModel: undefined, sortValue: undefined }
14 if (!req.query.sort) req.query.sort = '-createdAt'
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
22 newSort.sortModel = 'Video'
25 newSort.sortValue = req.query.sort
27 req.query.sort = newSort
32 // ---------------------------------------------------------------------------