]>
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' | |
18b24b2d | 4 | import { logger, loggerTagsFactory } from '../../helpers/logger' |
10363c74 | 5 | import { areValidationErrors } from './shared' |
94a5ff8a | 6 | |
18b24b2d C |
7 | const lTags = loggerTagsFactory('validators', 'jobs') |
8 | ||
94a5ff8a | 9 | const 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 | ||
29 | export { | |
402145b8 | 30 | listJobsValidator |
94a5ff8a | 31 | } |