sort.ts 852 B

1234567891011121314151617181920212223242526272829
  1. import express from 'express'
  2. const setDefaultSort = setDefaultSortFactory('-createdAt')
  3. const setDefaultVideosSort = setDefaultSortFactory('-publishedAt')
  4. const setDefaultVideoRedundanciesSort = setDefaultSortFactory('name')
  5. const setDefaultSearchSort = setDefaultSortFactory('-match')
  6. const setBlacklistSort = setDefaultSortFactory('-createdAt')
  7. // ---------------------------------------------------------------------------
  8. export {
  9. setDefaultSort,
  10. setDefaultSearchSort,
  11. setDefaultVideosSort,
  12. setDefaultVideoRedundanciesSort,
  13. setBlacklistSort
  14. }
  15. // ---------------------------------------------------------------------------
  16. function setDefaultSortFactory (sort: string) {
  17. return (req: express.Request, res: express.Response, next: express.NextFunction) => {
  18. if (!req.query.sort) req.query.sort = sort
  19. return next()
  20. }
  21. }