]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/jobs.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / jobs.ts
CommitLineData
94a5ff8a 1import * as express from 'express'
1061c73f
C
2import { param, query } from 'express-validator'
3import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs'
18b24b2d 4import { logger, loggerTagsFactory } from '../../helpers/logger'
94a5ff8a
C
5import { areValidationErrors } from './utils'
6
18b24b2d
C
7const lTags = loggerTagsFactory('validators', 'jobs')
8
94a5ff8a 9const listJobsValidator = [
402145b8
C
10 param('state')
11 .optional()
12 .custom(isValidJobState).not().isEmpty().withMessage('Should have a valid job state'),
13
1061c73f
C
14 query('jobType')
15 .optional()
16 .custom(isValidJobType).withMessage('Should have a valid job state'),
94a5ff8a 17
1061c73f 18 (req: express.Request, res: express.Response, next: express.NextFunction) => {
18b24b2d 19 logger.debug('Checking listJobsValidator parameters.', { parameters: req.params, ...lTags() })
94a5ff8a
C
20
21 if (areValidationErrors(req, res)) return
22
23 return next()
24 }
25]
26
27// ---------------------------------------------------------------------------
28
29export {
402145b8 30 listJobsValidator
94a5ff8a 31}