import express from 'express' ; import { SortType } from '../models/utils' ; const setDefaultSort = setDefaultSortFactory ( '-createdAt' ) ; const setDefaultVideosSort = setDefaultSortFactory ( '-publishedAt' ) ; const setDefaultVideoRedundanciesSort = setDefaultSortFactory ( 'name' ) ; const setDefaultSearchSort = setDefaultSortFactory ( '-match' ) ; function setBlacklistSort ( req , res , next ) { const newSort = { sortModel : undefined , sortValue : '' } ; if ( ! req . query . sort ) req . query . sort = '-createdAt' ; if ( req . query . sort === '-createdAt' || req . query . sort === 'createdAt' || req . query . sort === '-id' || req . query . sort === 'id' ) { newSort . sortModel = undefined ; } else { newSort . sortModel = 'Video' ; } newSort . sortValue = req . query . sort ; req . query . sort = newSort ; return next ( ) ; } export { setDefaultSort , setDefaultSearchSort , setDefaultVideosSort , setDefaultVideoRedundanciesSort , setBlacklistSort } ; function setDefaultSortFactory ( sort ) { return ( req , res , next ) => { if ( ! req . query . sort ) req . query . sort = sort ; return next ( ) ; } ; }