aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/jobs.ts
blob: 4de90548b067e9ab3378fb4dd26260e88e326599 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import express from 'express'
import { param, query } from 'express-validator'
import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs'
import { logger, loggerTagsFactory } from '../../helpers/logger'
import { areValidationErrors } from './shared'

const lTags = loggerTagsFactory('validators', 'jobs')

const listJobsValidator = [
  param('state')
  .optional()
  .custom(isValidJobState).not().isEmpty().withMessage('Should have a valid job state'),

  query('jobType')
    .optional()
    .custom(isValidJobType).withMessage('Should have a valid job state'),

  (req: express.Request, res: express.Response, next: express.NextFunction) => {
    logger.debug('Checking listJobsValidator parameters.', { parameters: req.params, ...lTags() })

    if (areValidationErrors(req, res)) return

    return next()
  }
]

// ---------------------------------------------------------------------------

export {
  listJobsValidator
}