better request validation

This commit is contained in:
Miodec 2022-11-15 16:40:19 +01:00
parent c34b56bc50
commit f76849f921

View file

@ -39,9 +39,9 @@ router.post(
RateLimit.newQuotesAdd,
validateRequest({
body: {
text: joi.string().min(60).required(),
source: joi.string().required(),
language: joi.string().required(),
text: joi.string().min(60).regex(/^\w+$/).required(),
source: joi.string().regex(/^\w+$/).required(),
language: joi.string().regex(/^\w+$/).required(),
captcha: joi.string().required(),
},
validationErrorMessage: "Please fill all the fields",
@ -56,8 +56,8 @@ router.post(
validateRequest({
body: {
quoteId: joi.string().required(),
editText: joi.string().allow(null),
editSource: joi.string().allow(null),
editText: joi.string().regex(/^\w+$/).allow(null),
editSource: joi.string().regex(/^\w+$/).allow(null),
},
validationErrorMessage: "Please fill all the fields",
}),
@ -85,7 +85,7 @@ router.get(
validateRequest({
query: {
quoteId: joi.string().regex(/^\d+$/).required(),
language: joi.string().required(),
language: joi.string().regex(/^\w+$/).required(),
},
}),
asyncHandler(QuoteController.getRating)
@ -99,7 +99,7 @@ router.post(
body: {
quoteId: joi.number().required(),
rating: joi.number().min(1).max(5).required(),
language: joi.string().required(),
language: joi.string().regex(/^\w+$/).required(),
},
}),
asyncHandler(QuoteController.submitRating)
@ -118,7 +118,7 @@ router.post(
validateRequest({
body: {
quoteId: joi.string().required(),
quoteLanguage: joi.string().required(),
quoteLanguage: joi.string().regex(/^\w+$/).required(),
reason: joi
.string()
.valid(
@ -128,7 +128,7 @@ router.post(
"Incorrect source"
)
.required(),
comment: joi.string().allow("").max(250).required(),
comment: joi.string().allow("").regex(/^\w+$/).max(250).required(),
captcha: joi.string().required(),
},
}),