]>
Commit | Line | Data |
---|---|---|
94a5ff8a | 1 | import * as express from 'express' |
1061c73f C |
2 | import { param, query } from 'express-validator' |
3 | import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs' | |
94a5ff8a C |
4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | |
6 | ||
7 | const listJobsValidator = [ | |
402145b8 C |
8 | param('state') |
9 | .optional() | |
10 | .custom(isValidJobState).not().isEmpty().withMessage('Should have a valid job state'), | |
11 | ||
1061c73f C |
12 | query('jobType') |
13 | .optional() | |
14 | .custom(isValidJobType).withMessage('Should have a valid job state'), | |
94a5ff8a | 15 | |
1061c73f | 16 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
94a5ff8a C |
17 | logger.debug('Checking listJobsValidator parameters.', { parameters: req.params }) |
18 | ||
19 | if (areValidationErrors(req, res)) return | |
20 | ||
21 | return next() | |
22 | } | |
23 | ] | |
24 | ||
25 | // --------------------------------------------------------------------------- | |
26 | ||
27 | export { | |
402145b8 | 28 | listJobsValidator |
94a5ff8a | 29 | } |