Improve validation and error handling on form field

This commit is contained in:
Burak Arslan committed 2025-08-06 00:53:35 +03:00
1 parent 0ea3379397
commit 4c2c452b91
9 files changed
+35 -13

No files matched your search

+11 -4
View File
@@ -184,12 +184,12 @@ const monitorValidation = joi.object({
.min(1)
.max(65535)
.when("type", {
is: "port",
then: joi.number().messages({
is: joi.valid("port", "game"),
then: joi.required().messages({
"number.base": "Port must be a number.",
"number.min": "Port must be at least 1.",
"number.max": "Port must be at most 65535.",
"any.required": "Port is required for port monitors.",
"any.required": "Port is required for port and game monitors.",
}),
otherwise: joi.optional(),
}),
@@ -205,7 +205,14 @@ const monitorValidation = joi.object({
expectedValue: joi.string().allow(null, ""),
jsonPath: joi.string().allow(null, ""),
matchMethod: joi.string().allow(null, ""),
gameId: joi.string().allow(null, ""),
gameId: joi.when("type", {
is: "game",
then: joi.string().required().messages({
"string.empty": "Game selection is required for game monitors.",
"any.required": "Game selection is required for game monitors.",
}),
otherwise: joi.string().allow(null, ""),
}),
});
const imageValidation = joi.object({