X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fsort.ts;h=cdb809e75e80084d5f6774e4f21ba4159be89fee;hb=4195cd2bc5046d4cdf1c677c27cd41f427d7a13a;hp=ab9ccf5242bee9af0f6f56eab779534037dd19f1;hpb=65fcc3119c334b75dd13bcfdebf186afdc580a8f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts index ab9ccf524..cdb809e75 100644 --- a/server/middlewares/sort.ts +++ b/server/middlewares/sort.ts @@ -1,17 +1,30 @@ -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() } @@ -19,7 +32,6 @@ function setVideosSort (req, res, next) { // --------------------------------------------------------------------------- export { - setUsersSort, - setVideoAbusesSort, - setVideosSort + setDefaultSort, + setBlacklistSort }