const joi = require("joi");
const validation = joi.object({
userName: joi.string().alphanum().min(3).max(25).trim(true).required(),
email: joi.string().email().trim(true).required(),
password: joi.string().min(8).trim(true).required(),
mobileNumber: joi.string().length(10).pattern(/[6-9]{1}[0-9]{9}/).required(),
birthYear: joi.number().integer().min(1920).max(2000),
skillSet: joi.array().items(joi.string().alphanum().trim(true)).default([]),
is_active: joi.boolean().default(true),
});
const schema = Joi.array().unique((a, b) => a.property === b.property);
Joi.object().keys({
contact: Joi.object().keys({
first_name: Joi.string(),
last_name: Joi.string(),
phone: Joi.string(),
}),
address: Joi.object().keys({
place: Joi.string(),
city: Joi.string().min(2).max(30),
street: Joi.string(),
house_number: Joi.string()
}).when('contact', {
is: Joi.object().keys({
first_name: Joi.exist(),
last_name: Joi.exist(),
phone: Joi.exist(),
}),
then: Joi.object({ place: Joi.required() }).required(),
otherwise: Joi.object({ place: Joi.forbidden() })
}),
passengers_amount: Joi.number(),
notes: Joi.string()
});
joi validation
const schema = Joi.object({
username: Joi.string()
.alphanum()
.min(3)
.max(30)
.required(),
});
schema.validate({ username: 'abc', birth_year: 1994 });
function responseValidate(response) {
const schema = {
id: Joi.objectId().required(),
response: Joi.string().min(3).max(512).required()
};
return schema.validate(response);
}