Skip to content

Applying raw after successful validation #1972

@kasperekt

Description

@kasperekt

Describe the problem you are trying to fix (provide as much context as possible)

I have an issue with compare dates of certain format using .min() and .ref() methods.
Basically, what I need is comparing two dates and checking whether one is less or equal to another. There's a catch, I need to use raw() to ensure that dates are still in string format.

Let's consider this example:

const schema = Joi.object({
  from: Joi.date().format('YYYY-MM-DD').raw().required(),
  to: Joi.date().format('YYYY-MM-DD').min(Joi.ref('from')).raw().required()
})

const payload = {from: '2019-10-19', to: '2019-10-19'}

I would expect that payload would pass validation. But it doesn't. I get an error where .min() condition is not satisfied. When I remove raw() it works great, but I don't have dates as a string format.

Is there any way to achieve my goal with current API?

Which API (or modification of the current API) do you suggest to solve that problem ?

I'm using version 15.0.1 of @hapi/joi package together with 1.3.0 version @hapi/joi-date package, so it's not base package only.

Are you ready to work on a pull request if your suggestion is accepted ?

Yes, I would be glad to help.

Metadata

Metadata

Assignees

Labels

breaking changesChange that can breaking existing codefeatureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions