This is my Joi validation:
let schema = Joi.object().keys({
personal_info: Joi.object().keys({
first_name: Joi.string().min(2).max(10).regex(Regex.alphabeta, 'alphabeta').required().error(JoiCustomErrors),
last_name: Joi.string().min(2).max(10).regex(Regex.alphabeta, 'alphabeta').required().error(JoiCustomErrors),
phone: Joi.string().min(10).max(10).regex(Regex.num, 'num').required().error(JoiCustomErrors),
nickname: Joi.string().min(3).max(12).regex(Regex.alphanum, 'alphanum').required().error(JoiCustomErrors),
birthday: Joi.date().max(`01-01-${new Date().getFullYear()-8}`).required().error(JoiCustomErrors),
IDNumber: Joi.string().min(9).max(9).regex(Regex.num, 'num').required().error(JoiCustomErrors),
address: Joi.object().keys({
city: Joi.string().valid(Cities).required().error(JoiCustomErrors),
street: Joi.string().min(2).max(15).regex(Regex.alphabeta, 'alphabeta').required().error(JoiCustomErrors),
house_number: Joi.string().min(1).max(5).regex(Regex.alphanum, 'alphanum').error(JoiCustomErrors)
})
}),
permission_level: Joi.number().min(1).max(9).required().error(JoiCustomErrors)
});
Joi.validate(req.body, schema, { abortEarly: false }, (err) => {
if (err) return cast.joiError(err);
return create_employee(result);
});
Explain:
All nested keys that are inside personal_info object are not getting checked. That means - If I take first_name and put it on parent (not under personal_info) it's getting checked by the schema validator - as should be.
What am I doing wrong?
personal_infoare not getting checked. That means - If i takefirst_nameand put it on parent (not underpersonal_info) it's getting checked by the schema validator. - Raz Buchnik