]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/search.ts
Support logout and add id and pass tests
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / search.ts
1 import * as express from 'express'
2 import { areValidationErrors } from './utils'
3 import { logger } from '../../helpers/logger'
4 import { query } from 'express-validator'
5 import { isDateValid } from '../../helpers/custom-validators/misc'
6
7 const videosSearchValidator = [
8 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
9
10 query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'),
11 query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'),
12
13 query('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'),
14 query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'),
15
16 query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
17 query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
18
19 (req: express.Request, res: express.Response, next: express.NextFunction) => {
20 logger.debug('Checking videos search query', { parameters: req.query })
21
22 if (areValidationErrors(req, res)) return
23
24 return next()
25 }
26 ]
27
28 const videoChannelsSearchValidator = [
29 query('search').not().isEmpty().withMessage('Should have a valid search'),
30
31 (req: express.Request, res: express.Response, next: express.NextFunction) => {
32 logger.debug('Checking video channels search query', { parameters: req.query })
33
34 if (areValidationErrors(req, res)) return
35
36 return next()
37 }
38 ]
39
40 // ---------------------------------------------------------------------------
41
42 export {
43 videoChannelsSearchValidator,
44 videosSearchValidator
45 }