]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/sort.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / server / middlewares / sort.ts
index ab9ccf5242bee9af0f6f56eab779534037dd19f1..8c27e82379bfbb2b09f04b1bd249ea859ab9f2f3 100644 (file)
@@ -1,25 +1,43 @@
-function setUsersSort (req, res, next) {
+import * as express from 'express'
+import { SortType } from '../models/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) {
-  if (!req.query.sort) req.query.sort = '-createdAt'
+function setDefaultSearchSort (req: express.Request, res: express.Response, next: express.NextFunction) {
+  if (!req.query.sort) req.query.sort = '-match'
 
   return next()
 }
 
-function setVideosSort (req, res, next) {
+function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
+  let newSort: SortType = { sortModel: undefined, sortValue: '' }
+
   if (!req.query.sort) req.query.sort = '-createdAt'
 
+  // 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'
+  }
+
+  newSort.sortValue = req.query.sort
+
+  req.query.sort = newSort
+
   return next()
 }
 
 // ---------------------------------------------------------------------------
 
 export {
-  setUsersSort,
-  setVideoAbusesSort,
-  setVideosSort
+  setDefaultSort,
+  setDefaultSearchSort,
+  setBlacklistSort
 }