Skip to content

Actual validation logic along with type check #2376

@taman9333

Description

@taman9333

Support plan

  • which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise):
  • is this issue currently blocking your project? (yes/no):
  • is this issue affecting a production system? (yes/no):

Context

  • node version: v13.6.0
  • module version: 17.1.1
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information: N/A

How can we help?

I was searching to make actual validation logic along with data format or type check.
for example: define and check if a record with id (given in the input params) exists.
I've tried external but the problem is value is not replaced so I have to fetch the object again after the validation

async function method(id) {
  const user = await User.findById(id)
  if !_.isNil(user) {
    return new Error("user is not found");
  } else {
    return user
  }
}

const schema = Joi.object({
  name: Joi.string().required(),
  id: Joi.number().external(method, "custom validation")
})

so I am asking if that's supported

an example from ruby code

 params do
    required(:room_id).value(:integer)
    required(:user_id).value(:integer)
    required(:start_date).value(:time)
    required(:end_date).value(:time)
    optional(:notes).value(:string)
  end

  rule(:room_id) do
    room = Room.find_by(id: value)

    if room.present?
      values[:room] = room
    else
      key.failure('could not be found')
    end
  end

Metadata

Metadata

Assignees

Labels

supportQuestions, discussions, and general support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions