У меня есть схема, которую я хочу проверить с помощью Ojbect.and()
.
const schema = Joi.object().keys({
username: Joi.string().alphanum().min(3).max(30).required(),
password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/),
access_token: [Joi.string(), Joi.number()],
birthyear: Joi.number().integer().min(1900).max(2013),
email: Joi.string().email(),
nickname: Joi.string()
}).and('username', 'birthyear', 'nickname').without('password', 'access_token');
По умолчанию возвращается сообщение об ошибке проверки типа.
"\"value\" contains [username] without its required peers [birthyear, nickname]"
Я хочу, чтобы он возвращал пользовательское сообщение об ошибке, например.
Username, Birthyer and Nick name all are required!
Для пользовательского сообщения произнесите nickname
Я бы сделал что-то вроде ниже
Joi.string().messages({ 'string.base' : "Nickname should be string!"})
Итак, я попробовал ниже, но это не работает.
const schema = Joi.object().keys({
username: Joi.string().alphanum().min(3).max(30).required(),
password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/),
access_token: [Joi.string(), Joi.number()],
birthyear: Joi.number().integer().min(1900).max(2013),
email: Joi.string().email(),
nickname: Joi.string()
})
.and('username', 'birthyear', 'nickname').without('password', 'access_token')
.messages({ 'Object.and' : "Username, Birthyear and Nick name all are required!"})
Как я могу сделать то же самое для Object.and
сообщения об ошибке проверки?