X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fjobs.ts;h=4de90548b067e9ab3378fb4dd26260e88e326599;hb=743dab5517d4501f6b35cfc795de6c8b6f41ebb3;hp=0fc183c1af9267b4c05d9c7ea6a40c11c65b572e;hpb=040d6896a3cd5622e78cccdedd8cce2afcf49a31;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/jobs.ts b/server/middlewares/validators/jobs.ts index 0fc183c1a..4de90548b 100644 --- a/server/middlewares/validators/jobs.ts +++ b/server/middlewares/validators/jobs.ts @@ -1,29 +1,22 @@ -import * as express from 'express' +import express from 'express' import { param, query } from 'express-validator' import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs' -import { logger } from '../../helpers/logger' -import { areValidationErrors } from './utils' +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 }) - - if (areValidationErrors(req, res)) return - - return next() - } -] - -const listJobsStateValidator = [ - param('state') - .custom(isValidJobState).not().isEmpty().withMessage('Should have a valid job state'), - - (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking listJobsValidator parameters.', { parameters: req.params }) + logger.debug('Checking listJobsValidator parameters.', { parameters: req.params, ...lTags() }) if (areValidationErrors(req, res)) return @@ -34,6 +27,5 @@ const listJobsStateValidator = [ // --------------------------------------------------------------------------- export { - listJobsValidator, - listJobsStateValidator + listJobsValidator }