1 import * as express from 'express'
2 import { SortType } from '../models/utils'
4 const setDefaultSort = setDefaultSortFactory('-createdAt')
6 const setDefaultVideoRedundanciesSort = setDefaultSortFactory('name')
8 const setDefaultSearchSort = setDefaultSortFactory('-match')
10 function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
11 const newSort: SortType = { sortModel: undefined, sortValue: '' }
13 if (!req.query.sort) req.query.sort = '-createdAt'
15 // Set model we want to sort onto
16 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
17 req.query.sort === '-id' || req.query.sort === 'id') {
18 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
19 newSort.sortModel = undefined
21 newSort.sortModel = 'Video'
24 newSort.sortValue = req.query.sort
26 req.query.sort = newSort
31 // ---------------------------------------------------------------------------
36 setDefaultVideoRedundanciesSort,
40 // ---------------------------------------------------------------------------
42 function setDefaultSortFactory (sort: string) {
43 return (req: express.Request, res: express.Response, next: express.NextFunction) => {
44 if (!req.query.sort) req.query.sort = sort