I'm using hapijs to write a microservice. I have an API that takes three parameters in the request body (POST method)
- UserID
- Last name
- Date of birth
I'm planning to do validation using JOI. The validation should be the following
The UserID should be required if both last name and date of birth are absent in the request
Both Last name and date of birth should be required if UserID is absent
I have tried to achieve that by following. It doesn't seem to work.
export const userRequestModel = Joi.object().keys({
lastname: Joi.string().when('uid',
{
is: undefined,
then: Joi.string().required()
}),
dob: Joi.string().when('uid',
{
is: undefined,
then: Joi.string().required()
}),
uid: Joi.string().
when('lastname',
{
is: undefined,
then: Joi.string().required()
}).
concat(Joi.string().when('dob',
{
is: undefined,
then: Joi.string().required()
}))
});
The concatenation doesn't seem to be syntactically correct. It shows the below typing error
Argument of type 'AlternativesSchema' is not assignable to parameter of type 'FunctionSchema'.Property 'arity' is missing in type 'AlternativesSchema'.