Skip to content

Empty object in Dynamo DB when using conditional validation #224

@aaronjhoffman

Description

@aaronjhoffman

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions