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

Bug no RequiredFieldValidation para fields com valor 0 #58

Open
PauloFavero opened this issue Mar 30, 2022 · 0 comments
Open

Bug no RequiredFieldValidation para fields com valor 0 #58

PauloFavero opened this issue Mar 30, 2022 · 0 comments

Comments

@PauloFavero
Copy link

Olá

O RequiredFieldValidation verifica apenas se o valor do campo é false. Isso ocasiona erros de validação quando um para um field com valor 0. Por exemplo:

const test = {
 distance: 0
}

Nesse caso o RequiredFieldValidation vai retornar missingParam 'distance'.

Uma solução seria:

  validate (data: any): Error {
    if (data[this.fieldName] === undefined || data[this.fieldName] === null) {
      return new MissingParamError(this.fieldName)
    }
  }

Abraços

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

No branches or pull requests

1 participant