-function setUsersSort (req, res, next) {
+import * as express from 'express'
+import 'express-validator'
+import { SortType } from '../helpers/utils'
+
+function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {
if (!req.query.sort) req.query.sort = '-createdAt'
return next()
}
-function setVideoAbusesSort (req, res, next) {
+function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
+ let newSort: SortType = { sortModel: undefined, sortValue: undefined }
+
if (!req.query.sort) req.query.sort = '-createdAt'
- return next()
-}
+ // Set model we want to sort onto
+ if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
+ req.query.sort === '-id' || req.query.sort === 'id') {
+ // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
+ newSort.sortModel = undefined
+ } else {
+ newSort.sortModel = 'Video'
+ }
-function setVideosSort (req, res, next) {
- if (!req.query.sort) req.query.sort = '-createdAt'
+ newSort.sortValue = req.query.sort
+
+ req.query.sort = newSort
return next()
}
// ---------------------------------------------------------------------------
export {
- setUsersSort,
- setVideoAbusesSort,
- setVideosSort
+ setDefaultSort,
+ setBlacklistSort
}