You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When calling the find method, the Herbs2Mongo Repository calls a method of the DataMapper class to convert each line returned into an entity type from @herbsjs/gotu, however, when the function returns, it fills in the fields of the entity that were not returned from the database, with a string containing the word undefined, instead of the javascript type undefined.
This can lead to several failures, since in checker.isEmpty the string "undefined" is not considered empty, while the type undefined is.
To Reproduce
Steps to reproduce the behavior:
Create a project that uses Herbs2Mongo, configure a User entity with the fields id, nickname, type and password, being the type field of type String.
Include only id, nickname and password fields.
Call the find function in the user search usecase.
The type field will contain a string containing the word undefined
Expected behavior
It is expected that the fields declared in the entity that are not in the database, or are returned as undefined, or that the key is not even included in the return object.
It is up to the user to verify using .isValid() or checking the fields, as well as treating entities that do not have certain fields according to business rules.
Screenshots
Evidence of returning the array of entities containing "undefined" after calling the toEntity method of the DataMapper class.
Location in the DataMapper class where the bug is most likely happening.
Additional context
I found this bug when searching for a list of customers, which had the _id and chat_id fields, but the new version of my product would now have the additional fields: username, group and type.
I would have a business rule to check if type was null or undefined using the herbsjs checker, and then ask those users to update their registration.
The problem happens because the dataParser function only checks if the field is strictly equal to null, however if the field does not exist in the database, it will be undefined and not null.
Then it passes to the parser an undefined, which returns a string written "undefined"
We can use a comparison if it's null or undefined to return null.
Using checker.isEmpty null, undefined, {} or "" values will be returned by themselves, without being
converted to null or undefined and without being passed to the parser.
BREAKING CHANGE: This can change the way a value that does not exist in the collection is
undefined in the application that uses the lib.
A null value is returned as null, but an
undefined is passed to the parser and can return a different value.
Instead of "undefined",
undefined will be returned, causing breaking changes in systems that expect "undefined" with a
string type.
herbsjs#36 and herbsjs#39
Describe the bug
When calling the find method, the Herbs2Mongo Repository calls a method of the DataMapper class to convert each line returned into an entity type from
@herbsjs/gotu
, however, when the function returns, it fills in the fields of the entity that were not returned from the database, with a string containing the word undefined, instead of the javascript type undefined.This can lead to several failures, since in
checker.isEmpty
the string"undefined"
is not considered empty, while the type undefined is.To Reproduce
Steps to reproduce the behavior:
Expected behavior
It is expected that the fields declared in the entity that are not in the database, or are returned as undefined, or that the key is not even included in the return object.
It is up to the user to verify using
.isValid()
or checking the fields, as well as treating entities that do not have certain fields according to business rules.Screenshots
Evidence of returning the array of entities containing "undefined" after calling the toEntity method of the DataMapper class.
Location in the DataMapper class where the bug is most likely happening.
Additional context
I found this bug when searching for a list of customers, which had the
_id
andchat_id
fields, but the new version of my product would now have the additional fields:username
,group
andtype
.I would have a business rule to check if type was null or undefined using the herbsjs checker, and then ask those users to update their registration.
As a temporary solution, I changed the check to verify that the resulting string was strictly equal to
"undefined"
https://github.com/vitorgamer58/telegram-bot-bovespa-herbs/blob/master/src/domain/usecases/verificaCadastro.js#L60
The text was updated successfully, but these errors were encountered: