Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Schema): support nested object check with checkForField and checkForFieldAsync #76

Merged
merged 4 commits into from
Apr 9, 2024

Conversation

simonguo
Copy link
Member

@simonguo simonguo commented Apr 8, 2024

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' }

@simonguo simonguo merged commit e315aec into master Apr 9, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant