]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/logs.ts
Add tags to AP rate logger
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / logs.ts
index 7380c6edde6a174fb7fdf1656e8b86a686f25d9a..ba817d9a9e19a418d297511883be3119aa29977a 100644 (file)
@@ -2,18 +2,18 @@ import * as express from 'express'
 import { logger } from '../../helpers/logger'
 import { areValidationErrors } from './utils'
 import { isDateValid } from '../../helpers/custom-validators/misc'
-import { query } from 'express-validator/check'
+import { query } from 'express-validator'
 import { isValidLogLevel } from '../../helpers/custom-validators/logs'
 
 const getLogsValidator = [
   query('startDate')
-    .custom(isDateValid).withMessage('Should have a valid start date'),
+    .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
   query('level')
     .optional()
     .custom(isValidLogLevel).withMessage('Should have a valid level'),
   query('endDate')
     .optional()
-    .custom(isDateValid).withMessage('Should have a valid end date'),
+    .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'),
 
   (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking getLogsValidator parameters.', { parameters: req.query })
@@ -24,8 +24,25 @@ const getLogsValidator = [
   }
 ]
 
+const getAuditLogsValidator = [
+  query('startDate')
+    .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
+  query('endDate')
+    .optional()
+    .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
+
+  (req: express.Request, res: express.Response, next: express.NextFunction) => {
+    logger.debug('Checking getAuditLogsValidator parameters.', { parameters: req.query })
+
+    if (areValidationErrors(req, res)) return
+
+    return next()
+  }
+]
+
 // ---------------------------------------------------------------------------
 
 export {
-  getLogsValidator
+  getLogsValidator,
+  getAuditLogsValidator
 }