34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
|
import * as express from 'express'
|
||
|
import { paginationValidator } from '../../middlewares/validators/pagination'
|
||
|
import { setDefaultPagination } from '../../middlewares/pagination'
|
||
|
import { asyncMiddleware } from '../../middlewares/async'
|
||
|
import { getFormattedObjects } from '../../helpers/utils'
|
||
|
import { queryVideos } from '../../lib/elastic-search-videos'
|
||
|
import { videosSearchSortValidator } from '../../middlewares/validators/sort'
|
||
|
import { commonVideosFiltersValidator, videosSearchValidator } from '../../middlewares/validators/search'
|
||
|
import { setDefaultSearchSort } from '../../middlewares/sort'
|
||
|
|
||
|
const searchRouter = express.Router()
|
||
|
|
||
|
searchRouter.get('/videos',
|
||
|
paginationValidator,
|
||
|
setDefaultPagination,
|
||
|
videosSearchSortValidator,
|
||
|
setDefaultSearchSort,
|
||
|
commonVideosFiltersValidator,
|
||
|
videosSearchValidator,
|
||
|
asyncMiddleware(searchVideos)
|
||
|
)
|
||
|
|
||
|
// ---------------------------------------------------------------------------
|
||
|
|
||
|
export { searchRouter }
|
||
|
|
||
|
// ---------------------------------------------------------------------------
|
||
|
|
||
|
async function searchVideos (req: express.Request, res: express.Response) {
|
||
|
const resultList = await queryVideos(req.body)
|
||
|
|
||
|
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||
|
}
|