2021-08-27 12:32:44 +00:00
|
|
|
import express from 'express'
|
2019-12-04 13:49:59 +00:00
|
|
|
import { param, query } from 'express-validator'
|
|
|
|
import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs'
|
2021-03-09 08:22:05 +00:00
|
|
|
import { logger, loggerTagsFactory } from '../../helpers/logger'
|
2021-06-03 15:33:44 +00:00
|
|
|
import { areValidationErrors } from './shared'
|
2018-01-25 14:05:18 +00:00
|
|
|
|
2021-03-09 08:22:05 +00:00
|
|
|
const lTags = loggerTagsFactory('validators', 'jobs')
|
|
|
|
|
2018-01-25 14:05:18 +00:00
|
|
|
const listJobsValidator = [
|
2020-12-14 11:00:35 +00:00
|
|
|
param('state')
|
2022-08-17 12:27:04 +00:00
|
|
|
.optional()
|
|
|
|
.custom(isValidJobState),
|
2020-12-14 11:00:35 +00:00
|
|
|
|
2019-12-04 13:49:59 +00:00
|
|
|
query('jobType')
|
|
|
|
.optional()
|
2022-08-17 12:27:04 +00:00
|
|
|
.custom(isValidJobType),
|
2018-01-25 14:05:18 +00:00
|
|
|
|
2019-12-04 13:49:59 +00:00
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2021-03-09 08:22:05 +00:00
|
|
|
logger.debug('Checking listJobsValidator parameters.', { parameters: req.params, ...lTags() })
|
2018-01-25 14:05:18 +00:00
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2020-12-14 11:00:35 +00:00
|
|
|
listJobsValidator
|
2018-01-25 14:05:18 +00:00
|
|
|
}
|