sepia-search-motore-di-rice.../server/middlewares/sort.ts

23 lines
574 B
TypeScript
Raw Normal View History

2022-06-03 10:54:30 +02:00
import express from 'express'
2020-02-13 11:49:03 +01:00
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
}