Reputation: 65
I'm tyring to valid req.body
, and the valid values is one item from the array.
Is there a way to do that?
Code:
updatePersonSchema = Joi.object({
personName: Joi.string().min(2).required(),
updateFiled: Joi.string().valid(personParams).required(), //oneOf the personParams
value: Joi.required()
})
Upvotes: 1
Views: 613
Reputation: 426
Yes you can pass an array to a valid function like this
const personParams = ['name', 'email', 'password']
updatePersonSchema = Joi.object({
personName: Joi.string().min(2).required(),
updateFiled: Joi.string().valid(...personParams).required(), //oneOf the personParams
value: Joi.required()
})
Upvotes: 2