X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fsort.ts;h=5120804b3a34b27dc88753ff86cffd5906062ff9;hb=299474e8279675adb6c5ce140e7e39c6f3439453;hp=687ce097b7c8b2f32702df186fd63e8ceb7c1a94;hpb=792dbaf07f83fbe3f1d209cd9edf190442c7d2f3;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts index 687ce097b..5120804b3 100644 --- a/server/middlewares/sort.ts +++ b/server/middlewares/sort.ts @@ -1,29 +1,21 @@ -import 'express-validator' import * as express from 'express' +import 'express-validator' +import { SortType } from '../helpers/utils' -import { SortType } from '../helpers' -import { database } from '../initializers' - -function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { - if (!req.query.sort) req.query.sort = '-createdAt' - - return next() -} - -function setVideoAbusesSort (req: express.Request, res: express.Response, next: express.NextFunction) { +function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) { if (!req.query.sort) req.query.sort = '-createdAt' return next() } -function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) { - 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 setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) { - let newSort: SortType = { sortModel: undefined, sortValue: undefined } + let newSort: SortType = { sortModel: undefined, sortValue: '' } if (!req.query.sort) req.query.sort = '-createdAt' @@ -33,7 +25,7 @@ function setBlacklistSort (req: express.Request, res: express.Response, next: ex // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ... newSort.sortModel = undefined } else { - newSort.sortModel = database.Video + newSort.sortModel = 'Video' } newSort.sortValue = req.query.sort @@ -46,8 +38,7 @@ function setBlacklistSort (req: express.Request, res: express.Response, next: ex // --------------------------------------------------------------------------- export { - setUsersSort, - setVideoAbusesSort, - setVideosSort, + setDefaultSort, + setDefaultSearchSort, setBlacklistSort }