-
Notifications
You must be signed in to change notification settings - Fork 96
Description
Hello team!
I’ve run into a problem when adding addressSource during Google search on the “add property” page. In the web Google provider, this always triggers
apps/address-service/domains/common/utils/services/search/plugins/SearchByGooglePlaceId.js.
The s value passed into it is the googlePlaceId. Because of that, it’s not possible to search inside addressSource using a human-readable address string.
I’d like to update the createOrUpdateAddressWithSource function in
apps/address-service/domains/common/utils/services/search/searchServiceUtils.js.
The idea: additionally store in addressSource the value derived from the address field (schema). Then the search by human-readable string will work.
What do you think about this idea? Let me know!
Related issue: #6485
Current behavior
We only store one addressSource, built from the input parameter (with Google this is googlePlaceId):
//
// Address source
//
const compoundedAddressSource = mergeAddressAndHelpers(addressSource, helpers)
const addressSourceItem = await addressSourceServerUtils.getOne(context, { source: compoundedAddressSource.toLowerCase(), deletedAt: null }, ADDRESS_ITEM_FIELDS)
if (addressSourceItem) {
await addressSourceServerUtils.update(context, addressSourceItem.id, {
...dvSender,
source: compoundedAddressSource,
address: { connect: { id: addressItem.id } },
})
} else {
await addressSourceServerUtils.create(
context,
{
...dvSender,
source: compoundedAddressSource,
address: { connect: { id: addressItem.id } },
},
)
}Result: the stored value is derived from googlePlaceId (Example from admin/address-sources/:
source: googleplaceid:ejrdywxszsbkzsbsb3mgtgfnb3mgzgugq29yb25hcywgmjmsifphcmfnb3phlcbfc3bhw7fhijaslgouchijixmvcxjrwq0rhqc9b8o5ipgqfyouchijdudwzrjrwq0rjlwcpbire80)
Expected behavior
Store both variants:
- from the incoming
addressSource(includinggooglePlaceId); - from the actual textual value
addressItem.address.
Both are normalized via mergeAddressAndHelpers and then deduped.
Proposed fix
Add candidates and perform an idempotent upsert for each unique normalized source:
const addressSourceCandidates = [addressSource, addressItem.address]
const uniqueNormalizedSources = [
...new Set(
addressSourceCandidates
.map(item => mergeAddressAndHelpers(item, helpers))
.filter(Boolean)
)]
for (const uniqueSource of uniqueNormalizedSources) {
await upsertAddressSource(context, addressSourceServerUtils, dvSender, uniqueSource, addressItem.id)
}Helper:
async function upsertAddressSource (context, addressSourceServerUtils, dvSender, normalizedSource, addressId) {
if (!normalizedSource) return null
const existing = await addressSourceServerUtils.getOne(
context,
{ source: normalizedSource.toLowerCase(), deletedAt: null },
ADDRESS_ITEM_FIELDS
)
if (existing) {
await addressSourceServerUtils.update(context, existing.id, {
...dvSender,
source: normalizedSource,
address: { connect: { id: addressId } },
})
return existing.id
}
const created = await addressSourceServerUtils.create(context, {
...dvSender,
source: normalizedSource,
address: { connect: { id: addressId } },
})
return created?.id ?? null
}Steps to reproduce
- Open the “add property” page.
- Search an address via Google (plugin
SearchByGooglePlaceId.jsgetsgooglePlaceIdins). - Save.
- Try searching
addressSourceby a human-readable address string — nothing is found.
What do you think? If the approach looks good, I can send a PR.