1 import * as express from 'express'
2 import { SortType } from '../models/utils'
4 function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {
5 if (!req.query.sort) req.query.sort = '-createdAt'
10 function setDefaultSearchSort (req: express.Request, res: express.Response, next: express.NextFunction) {
11 if (!req.query.sort) req.query.sort = '-match'
16 function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
17 let newSort: SortType = { sortModel: undefined, sortValue: '' }
19 if (!req.query.sort) req.query.sort = '-createdAt'
21 // Set model we want to sort onto
22 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
23 req.query.sort === '-id' || req.query.sort === 'id') {
24 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
25 newSort.sortModel = undefined
27 newSort.sortModel = 'Video'
30 newSort.sortValue = req.query.sort
32 req.query.sort = newSort
37 // ---------------------------------------------------------------------------