const schema = new Schema({
url: StringType().isURL("Should be a url"),
user: ObjectType().shape({
email: StringType().isEmail("Should be an email"),
age: NumberType().min(18, "Age should be greater than 18"),
parent: ObjectType().shape({
email: StringType().isEmail("Should be an email"),
age: NumberType().min(50, "Age should be greater than 50"),
}),
}),
});
const checkResult = schema.checkForField(
"user.parent.age",
{ user: { parent: { age: 40 } } },
{ nestedObject: true }
);
// output
// { hasError: true, errorMessage: 'Age should be greater than 50' }