2020-02-13 11:49:03 +01:00
|
|
|
import * as express from 'express'
|
|
|
|
|
2020-02-14 16:14:45 +01:00
|
|
|
const setDefaultSort = setDefaultSortFactory('-createdAt')
|
2020-02-13 11:49:03 +01:00
|
|
|
|
2020-02-14 16:14:45 +01:00
|
|
|
const setDefaultSearchSort = setDefaultSortFactory('-match')
|
2020-02-13 11:49:03 +01:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2020-02-14 16:14:45 +01:00
|
|
|
setDefaultSort,
|
|
|
|
setDefaultSearchSort
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function setDefaultSortFactory (sort: string) {
|
|
|
|
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (!req.query.sort) req.query.sort = sort
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
2020-02-13 11:49:03 +01:00
|
|
|
}
|