This is my Joi schema
const createRoom = {
body: {
createdBy: Joi.string().required(),
members: Joi.array().min(2).max(2).items(
Joi.object().keys({
id: Joi.string().required(),
name: Joi.string().required(),
})
).unique('id').required()
}
}
What i want is
The value of
createdBymust match with one unique object id in members array
Example
This input should pass
{
createdBy: 'abcd1234',
members: [
{
id: 'abcd1234',
name: "john"
},
{
id: 'xyz1234',
name: "john"
}
]
}
This input should fail
{
createdBy: 'abcd1234',
members: [
{
id: 'bcdf1234',
name: "john"
},
{
id: 'xyz1234',
name: "john"
}
]
}
Is this possible with joi? I didn't find anything like this in Joi Docs.