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

Do not add key errors to the entity when there is no validation error. #71

Open
vitorgamer58 opened this issue Jun 29, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@vitorgamer58
Copy link

Is your feature request related to a problem? Please describe.
When I call the isValid function on my entity instance, it returns true or false, indicating whether or not my entity is valid.
Additionally, this function includes in my entity an errors key containing the errors that were detected in the validation, according to the rules defined in the entity.
However, even when there is no error, it still creates the errors key in the entity, containing an empty object.

This can lead to problems, for example if I pass the already validated entity to another usecase, or if I pass it to some function to insert into the database, which will insert the errors key containing an empty object.

Describe the solution you'd like
I believe we can make a conditional to only insert the errors key if there really is a validation error.
In the baseEntity.js file in the line that follows:

this.errors = errors

Describe alternatives you've considered
I have not considered alternatives to this feature.

Additional context
I noticed on two points:

  1. By adapting my project that uses herbs2mongo to save nested entities in the database.
  2. When using a usecase that passes the request it received (entity) to another usecase.

As a temporary fix, after verifying that the entity is valid, I deleted the errors field before calling the other usecase.

delete client.errors;

And in the database part, I changed my DataMapper instance to delete keys that I might configure when calling my deletekeys function, as already mentioned in this issue: herbsjs/herbs2mongo#35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant