]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/jobs.ts
add display of logs matching any state
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / jobs.ts
index 41a8d689962e6bcf6674d0f0c4c9a59ebce3fd36..0fc183c1af9267b4c05d9c7ea6a40c11c65b572e 100644 (file)
@@ -1,13 +1,28 @@
 import * as express from 'express'
-import { param } from 'express-validator'
-import { isValidJobState } from '../../helpers/custom-validators/jobs'
+import { param, query } from 'express-validator'
+import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs'
 import { logger } from '../../helpers/logger'
 import { areValidationErrors } from './utils'
 
 const listJobsValidator = [
-  param('state').custom(isValidJobState).not().isEmpty().withMessage('Should have a valid job state'),
+  query('jobType')
+    .optional()
+    .custom(isValidJobType).withMessage('Should have a valid job state'),
 
-  async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+  (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 })
 
     if (areValidationErrors(req, res)) return
@@ -19,5 +34,6 @@ const listJobsValidator = [
 // ---------------------------------------------------------------------------
 
 export {
-  listJobsValidator
+  listJobsValidator,
+  listJobsStateValidator
 }