1
0
Fork 0

improve api param message for dates

This commit is contained in:
Rigel Kent 2021-05-31 19:47:14 +02:00
parent 732c95cc97
commit 70330f6323
No known key found for this signature in database
GPG key ID: 5E53E96A494E452F
5 changed files with 19 additions and 11 deletions

View file

@ -14,7 +14,7 @@ const signatureValidator = [
.custom(isSignatureTypeValid).withMessage('Should have a valid signature type'), .custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
body('signature.created') body('signature.created')
.optional() .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') body('signature.creator')
.optional() .optional()
.custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'), .custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),

View file

@ -7,13 +7,13 @@ import { isValidLogLevel } from '../../helpers/custom-validators/logs'
const getLogsValidator = [ const getLogsValidator = [
query('startDate') 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') query('level')
.optional() .optional()
.custom(isValidLogLevel).withMessage('Should have a valid level'), .custom(isValidLogLevel).withMessage('Should have a valid level'),
query('endDate') query('endDate')
.optional() .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) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking getLogsValidator parameters.', { parameters: req.query }) logger.debug('Checking getLogsValidator parameters.', { parameters: req.query })
@ -26,10 +26,10 @@ const getLogsValidator = [
const getAuditLogsValidator = [ const getAuditLogsValidator = [
query('startDate') 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') query('endDate')
.optional() .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) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking getAuditLogsValidator parameters.', { parameters: req.query }) logger.debug('Checking getAuditLogsValidator parameters.', { parameters: req.query })

View file

@ -8,11 +8,19 @@ import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
const videosSearchValidator = [ const videosSearchValidator = [
query('search').optional().not().isEmpty().withMessage('Should have a valid search'), query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'), query('startDate')
query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'), .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 valid published start date'), query('originallyPublishedStartDate')
query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'), .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('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),

View file

@ -21,7 +21,7 @@ const userHistoryListValidator = [
const userHistoryRemoveValidator = [ const userHistoryRemoveValidator = [
body('beforeDate') body('beforeDate')
.optional() .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) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking userHistoryRemoveValidator parameters', { parameters: req.body }) logger.debug('Checking userHistoryRemoveValidator parameters', { parameters: req.body })

View file

@ -473,7 +473,7 @@ function getCommonVideoEditAttributes () {
.customSanitizer(toValueOrNull), .customSanitizer(toValueOrNull),
body('scheduleUpdate.updateAt') body('scheduleUpdate.updateAt')
.optional() .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') body('scheduleUpdate.privacy')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)