From 70330f63236a3200829f2ba76c10cca88326b858 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Mon, 31 May 2021 19:47:14 +0200 Subject: improve api param message for dates --- server/middlewares/validators/activitypub/signature.ts | 2 +- server/middlewares/validators/logs.ts | 8 ++++---- server/middlewares/validators/search.ts | 18 +++++++++++++----- server/middlewares/validators/user-history.ts | 2 +- server/middlewares/validators/videos/videos.ts | 2 +- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts index 7c4e49463..7896a6128 100644 --- a/server/middlewares/validators/activitypub/signature.ts +++ b/server/middlewares/validators/activitypub/signature.ts @@ -14,7 +14,7 @@ const signatureValidator = [ .custom(isSignatureTypeValid).withMessage('Should have a valid signature type'), body('signature.created') .optional() - .custom(isDateValid).withMessage('Should have a valid signature created date'), + .custom(isDateValid).withMessage('Should have a signature created date that conforms to ISO 8601'), body('signature.creator') .optional() .custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'), diff --git a/server/middlewares/validators/logs.ts b/server/middlewares/validators/logs.ts index 70e4d0d99..ba817d9a9 100644 --- a/server/middlewares/validators/logs.ts +++ b/server/middlewares/validators/logs.ts @@ -7,13 +7,13 @@ 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 }) @@ -26,10 +26,10 @@ const getLogsValidator = [ const getAuditLogsValidator = [ 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('endDate') .optional() - .custom(isDateValid).withMessage('Should have a valid end date'), + .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 }) diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index 78213c70d..d2f527750 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts @@ -8,11 +8,19 @@ import { isSearchTargetValid } from '@server/helpers/custom-validators/search' const videosSearchValidator = [ query('search').optional().not().isEmpty().withMessage('Should have a valid search'), - query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'), - query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'), - - query('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'), - query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'), + query('startDate') + .optional() + .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'), + + query('originallyPublishedStartDate') + .optional() + .custom(isDateValid).withMessage('Should have a published start date that conforms to ISO 8601'), + query('originallyPublishedEndDate') + .optional() + .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'), query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), diff --git a/server/middlewares/validators/user-history.ts b/server/middlewares/validators/user-history.ts index 058bf7758..647294cc3 100644 --- a/server/middlewares/validators/user-history.ts +++ b/server/middlewares/validators/user-history.ts @@ -21,7 +21,7 @@ const userHistoryListValidator = [ const userHistoryRemoveValidator = [ body('beforeDate') .optional() - .custom(isDateValid).withMessage('Should have a valid before date'), + .custom(isDateValid).withMessage('Should have a before date that conforms to ISO 8601'), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking userHistoryRemoveValidator parameters', { parameters: req.body }) diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 3219e10d4..dce02df18 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -473,7 +473,7 @@ function getCommonVideoEditAttributes () { .customSanitizer(toValueOrNull), body('scheduleUpdate.updateAt') .optional() - .custom(isDateValid).withMessage('Should have a valid schedule update date'), + .custom(isDateValid).withMessage('Should have a schedule update date that conforms to ISO 8601'), body('scheduleUpdate.privacy') .optional() .customSanitizer(toIntOrNull) -- cgit v1.2.3