Support body params
This commit is contained in:
parent
0feb8973a8
commit
c5e0f37c73
|
@ -27,7 +27,7 @@ export { searchChannelsRouter }
|
|||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function searchChannels (req: express.Request, res: express.Response) {
|
||||
const query = req.query as ChannelsSearchQuery
|
||||
const query = (req.query || req.body) as ChannelsSearchQuery
|
||||
const resultList = await queryChannels(query)
|
||||
|
||||
return res.json({
|
||||
|
|
|
@ -28,7 +28,7 @@ export { searchVideosRouter }
|
|||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function searchVideos (req: express.Request, res: express.Response) {
|
||||
const query = req.query as VideosSearchQuery
|
||||
const query = (req.query || req.body) as VideosSearchQuery
|
||||
|
||||
const resultList = await queryVideos(query)
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import * as express from 'express'
|
||||
import { query } from 'express-validator'
|
||||
import { check } from 'express-validator'
|
||||
import { logger } from '../../helpers/logger'
|
||||
import { areValidationErrors } from './utils'
|
||||
|
||||
const paginationValidator = [
|
||||
query('start').optional().isInt({ min: 0 }).withMessage('Should have a number start'),
|
||||
query('count').optional().isInt({ min: 0 }).withMessage('Should have a number count'),
|
||||
check('start').optional().isInt({ min: 0 }).withMessage('Should have a number start'),
|
||||
check('count').optional().isInt({ min: 0 }).withMessage('Should have a number count'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug({ parameters: req.query }, 'Checking pagination parameters')
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { query } from 'express-validator'
|
||||
import { check } from 'express-validator'
|
||||
import * as express from 'express'
|
||||
import { isDateValid, toArray } from '../../helpers/custom-validators/misc'
|
||||
import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../helpers/custom-validators/search-videos'
|
||||
|
@ -6,11 +6,11 @@ import { logger } from '../../helpers/logger'
|
|||
import { areValidationErrors } from './utils'
|
||||
|
||||
const commonFiltersValidators = [
|
||||
query('blockedAccounts')
|
||||
check('blockedAccounts')
|
||||
.optional()
|
||||
.customSanitizer(toArray)
|
||||
.custom(isStringArray).withMessage('Should have a valid blockedAccounts array'),
|
||||
query('blockedHosts')
|
||||
check('blockedHosts')
|
||||
.optional()
|
||||
.customSanitizer(toArray)
|
||||
.custom(isStringArray).withMessage('Should have a valid hosts array'),
|
||||
|
@ -25,27 +25,27 @@ const commonFiltersValidators = [
|
|||
]
|
||||
|
||||
const commonVideosFiltersValidator = [
|
||||
query('categoryOneOf')
|
||||
check('categoryOneOf')
|
||||
.optional()
|
||||
.customSanitizer(toArray)
|
||||
.custom(isNumberArray).withMessage('Should have a valid one of category array'),
|
||||
query('licenceOneOf')
|
||||
check('licenceOneOf')
|
||||
.optional()
|
||||
.customSanitizer(toArray)
|
||||
.custom(isNumberArray).withMessage('Should have a valid one of licence array'),
|
||||
query('languageOneOf')
|
||||
check('languageOneOf')
|
||||
.optional()
|
||||
.customSanitizer(toArray)
|
||||
.custom(isStringArray).withMessage('Should have a valid one of language array'),
|
||||
query('tagsOneOf')
|
||||
check('tagsOneOf')
|
||||
.optional()
|
||||
.customSanitizer(toArray)
|
||||
.custom(isStringArray).withMessage('Should have a valid one of tags array'),
|
||||
query('tagsAllOf')
|
||||
check('tagsAllOf')
|
||||
.optional()
|
||||
.customSanitizer(toArray)
|
||||
.custom(isStringArray).withMessage('Should have a valid all of tags array'),
|
||||
query('nsfw')
|
||||
check('nsfw')
|
||||
.optional()
|
||||
.custom(isNSFWQueryValid).withMessage('Should have a valid NSFW attribute'),
|
||||
|
||||
|
@ -59,16 +59,16 @@ const commonVideosFiltersValidator = [
|
|||
]
|
||||
|
||||
const videosSearchValidator = [
|
||||
query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
|
||||
check('search').optional().not().isEmpty().withMessage('Should have a valid search'),
|
||||
|
||||
query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'),
|
||||
query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'),
|
||||
check('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'),
|
||||
check('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'),
|
||||
|
||||
query('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'),
|
||||
query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'),
|
||||
check('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'),
|
||||
check('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'),
|
||||
|
||||
query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
|
||||
query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
|
||||
check('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
|
||||
check('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug({ parameters: req.query }, 'Checking videos search query')
|
||||
|
@ -80,7 +80,7 @@ const videosSearchValidator = [
|
|||
]
|
||||
|
||||
const videoChannelsSearchValidator = [
|
||||
query('search').not().isEmpty().withMessage('Should have a valid search'),
|
||||
check('search').not().isEmpty().withMessage('Should have a valid search'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug({ parameters: req.query }, 'Checking video channels search query')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as express from 'express'
|
||||
import { query, validationResult } from 'express-validator'
|
||||
import { check, validationResult } from 'express-validator'
|
||||
import { logger } from '../../helpers/logger'
|
||||
|
||||
function areValidationErrors (req: express.Request, res: express.Response) {
|
||||
|
@ -17,7 +17,7 @@ function areValidationErrors (req: express.Request, res: express.Response) {
|
|||
|
||||
function checkSort (sortableColumns: string[]) {
|
||||
return [
|
||||
query('sort').optional().isIn(sortableColumns).withMessage('Should have correct sortable column'),
|
||||
check('sort').optional().isIn(sortableColumns).withMessage('Should have correct sortable column'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug({ parameters: req.query }, 'Checking sort parameters')
|
||||
|
|
Loading…
Reference in New Issue