import { ModelValidator } from '@gnx-utilities/validators'
const user = {
name: 'John',
email: 'test@test.test',
age: 20
}
const validation = ModelValidator.create()
.for({ model: user })
.withProperty(({ name }) => name === 'John')
.withProperty(({ email }) => email === 'test@test.test')
.withProperty(({ age }) => age === 20)
console.log(validation.validate()) // true
console.log(validation.softValidation()) // { isValid: true, errors: [], totalErrors: 0 }
console.log(validation.getErrors()) // []
const wrongValidation = ModelValidator.create()
.for({ model: user })
.withProperty(({ name }) => name === 'Jane')
.withProperty(({ email }) => email === 'testing@test.com')
.withProperty(({ age }) => age === 50)
console.log(wrongValidation.validate()) // false
console.log(wrongValidation.softValidation()) // { isValid: false, errors: [ 'The property name is not valid', 'The property email is not valid', 'The property age is not valid' ], totalErrors: 3 }
console.log(wrongValidation.getErrors()) // [ 'The property name is not valid', 'The property email is not valid', 'The property age is not valid' ]