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