I have this joi schema using .number() for a body parameter 'public'
contactSchema: Joi.object().keys({
email: Joi.string().email().required(),
public: Joi.number().required()
}),
If I allow the paremeter to be 0 in some instance ...
if(req.session.sessionEmail){
var isPublic = 0;
} else {
var isPublic = 1;
}
... joi says its invalid.
If I don't pass a 0 ... all is good?
if(req.session.sessionEmail){
var isPublic = 2;
} else {
var isPublic = 1;
}
Why does it fail in case of 0?
https://github.com/hapijs/joi/blob/master/API.md#number---inherits-from-any
0in JS, it might be getting mixed up and seeing this as "falsey". From the docs there's a min function, wouldJoi.number().min(0)maybe work? Although, unless I am misunderstanding whatisPublicrepresents....wouldn't boolean() be more appropriate? - James