This commit is contained in:
Jake Kasper
2025-08-25 09:18:52 -04:00
parent 6c70ebe0ae
commit 792f186715
2 changed files with 19 additions and 9 deletions

View File

@@ -108,14 +108,17 @@ const userProductSchema = Joi.object({
Joi.string().allow(''),
Joi.allow(null)
).optional()
}).when('equipmentId', {
is: Joi.number().positive(),
then: Joi.object(), // When equipmentId is a positive number, spreaderBrand is optional
otherwise: Joi.object({
spreaderBrand: Joi.string().max(100).required() // When no valid equipmentId, require spreaderBrand
})
})
}).custom((value, helpers) => {
// Custom validation: require either equipmentId OR spreaderBrand
if (value.equipmentId || value.spreaderBrand) {
return value; // Valid if either exists
}
return helpers.error('custom.equipmentOrBrand');
}, 'Equipment or Brand validation')
).optional()
.messages({
'custom.equipmentOrBrand': 'Either equipmentId or spreaderBrand must be provided'
})
});
// Application validation schemas