open-condo-software / condo

Open source condominium management platform
MIT License
62 stars 26 forks source link

Mutation registerResident or Address Service Functionality Issue #5100

Open paulo-rossy opened 1 month ago

paulo-rossy commented 1 month ago

There seems to be a problem with the registerResident mutation or the address service functionality.

In my project, we're using the Google provider for addresses, which differs from the dadata provider logic.

When adding a building, the method search from SearchByGooglePlaceId is called. This method, in turn, invokes the createOrUpdateAddressWithSource function, where the second-to-last parameter is a search string (which is a Google Place ID).

return await createOrUpdateAddressWithSource(
    godContext,
    Address,
    AddressSource,
    addressData,
    s,
    dvSender,
);

Thus, the source field contains a string like: googlePlaceId:.

When performing the registerResident mutation, the address field is defined with the same value: googlePlaceId:.

In RegisterResidentService.js, the service tries to find an address with the given place_id on line 77:

const addressItem = await client.search(address)

The search by place_id works correctly since the place_id was added to the source field when the building was added.

However, in this service, the following call is made:

const resident = await ResidentAPI.create(context, residentAttrs)

Here, residentAttrs contains the address string instead of the place_id.

In the Resident schema, fields are retrieved from addressService (line 263), and these fields are passed to validateInput. The address from addressService returned is incorrect because it searches by address string rather than by ID.

As a result, the mutation request for registerResident returns the error: Cannot connect property, because its address differs from address of resident.

Additionally, please note that /search?s= behaves incorrectly. If a non-existent address is provided, it still returns values.

AleX83Xpert commented 3 weeks ago

Hi @paulo-rossy, thanks for your investigation and explanation. I've found a bug. If you try to search with Google provider by text you will receive an empty addressKey. Also, there are different responses from Google for searching by text and place id. It looks like we need to perform two requests: search by text, and then search by place id, because the first query has no information to build addressKey. I've opened a new PR to solve these problems and I'll notify you when all is done.

AleX83Xpert commented 3 weeks ago

Please check your database for an empty value in Address.key. These rows are erroneous.