aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/middlewares/sort.ts
blob: 77a532276d26de286b44ccb7c8700d82a4270504 (plain) (tree)
1
2
3
4
5
6
7
8
9
                             
 
                                                          
                                                                  
 
                                                                     
 
                                                            
                                                            
 

                                                                              
        
                 
                       
                       
                                  
                  
 









                                                                                       
import express from 'express'

const setDefaultSort = setDefaultSortFactory('-createdAt')
const setDefaultVideosSort = setDefaultSortFactory('-publishedAt')

const setDefaultVideoRedundanciesSort = setDefaultSortFactory('name')

const setDefaultSearchSort = setDefaultSortFactory('-match')
const setBlacklistSort = setDefaultSortFactory('-createdAt')

// ---------------------------------------------------------------------------

export {
  setDefaultSort,
  setDefaultSearchSort,
  setDefaultVideosSort,
  setDefaultVideoRedundanciesSort,
  setBlacklistSort
}

// ---------------------------------------------------------------------------

function setDefaultSortFactory (sort: string) {
  return (req: express.Request, res: express.Response, next: express.NextFunction) => {
    if (!req.query.sort) req.query.sort = sort

    return next()
  }
}