vogels
vogels copied to clipboard
Empty object in Dynamo DB when using conditional validation
I've been trying to add conditional validation in my schema using joi.when as following:
{
id: vogels.types.uuid(),
type: Joi.string().valid(['a','b']).required(),
time: Joi.object().keys({
start: Joi.date().required(),
end: Joi.date(),
}).required().when('type', { is: 'a', then: Joi.object({ end: Joi.required()}), otherwise: Joi.object({ end: Joi.valid(null)})}),
}
When trying to create new object using mytable.Create I'm getting result back correctly although in the db the field "time" is empty object {}
I've tested the data with the Joi schema and it's all valid, and as I said, even Vogels return the "saved" object correctly - but still in the DB the field is empty. When I'm removing the "when" condition, it's all working perfectly and the field is populated correctly in the DB.
Any help would be greatly appreciated on this.
Thanks in advance