]>
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 | query('jobType') | |
9 | .optional() | |
10 | .custom(isValidJobType).withMessage('Should have a valid job state'), | |
11 | ||
12 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
13 | logger.debug('Checking listJobsValidator parameters.', { parameters: req.params }) | |
14 | ||
15 | if (areValidationErrors(req, res)) return | |
16 | ||
17 | return next() | |
18 | } | |
19 | ] | |
20 | ||
21 | const listJobsStateValidator = [ | |
22 | param('state') | |
23 | .custom(isValidJobState).not().isEmpty().withMessage('Should have a valid job state'), | |
24 | ||
25 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
26 | logger.debug('Checking listJobsValidator parameters.', { parameters: req.params }) | |
27 | ||
28 | if (areValidationErrors(req, res)) return | |
29 | ||
30 | return next() | |
31 | } | |
32 | ] | |
33 | ||
34 | // --------------------------------------------------------------------------- | |
35 | ||
36 | export { | |
37 | listJobsValidator, | |
38 | listJobsStateValidator | |
39 | } |