fix(search): robust address from all structured fields, multi-address support
- Always build from structured fields first (street, postalNo, building, locality) - Fall back to addressDescription ONLY when no structured fields exist - Support multiple addresses per immovable (joined with |) - Deduplicate identical addresses - Handle addressDescription as last-resort fallback
This commit is contained in:
@@ -99,14 +99,14 @@ function persistWorkspace(siruta: string, workspacePk: number) {
|
|||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function formatAddress(item?: any) {
|
function formatAddress(item?: any) {
|
||||||
const address = item?.immovableAddresses?.[0]?.address ?? null;
|
const addresses = item?.immovableAddresses ?? [];
|
||||||
if (!address) return "";
|
if (addresses.length === 0) return "";
|
||||||
|
|
||||||
// If addressDescription is a clean string, use it
|
// Build from ALL addresses (some parcels have multiple)
|
||||||
if (address.addressDescription) {
|
const formatted: string[] = [];
|
||||||
const desc = String(address.addressDescription).trim();
|
for (const entry of addresses) {
|
||||||
if (desc.length > 3 && !desc.includes("[object")) return desc;
|
const address = entry?.address ?? entry;
|
||||||
}
|
if (!address) continue;
|
||||||
|
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
|
|
||||||
@@ -130,11 +130,11 @@ function formatAddress(item?: any) {
|
|||||||
const houseNo = address.postalNo ?? address.buildingNo ?? null;
|
const houseNo = address.postalNo ?? address.buildingNo ?? null;
|
||||||
if (houseNo) parts.push(`Nr. ${houseNo}`);
|
if (houseNo) parts.push(`Nr. ${houseNo}`);
|
||||||
|
|
||||||
// Building details (apartments, floors, etc.)
|
// Building details
|
||||||
|
if (address.buildingSectionNo) parts.push(`Bl. ${address.buildingSectionNo}`);
|
||||||
if (address.buildingEntryNo) parts.push(`Sc. ${address.buildingEntryNo}`);
|
if (address.buildingEntryNo) parts.push(`Sc. ${address.buildingEntryNo}`);
|
||||||
if (address.buildingFloorNo) parts.push(`Et. ${address.buildingFloorNo}`);
|
if (address.buildingFloorNo) parts.push(`Et. ${address.buildingFloorNo}`);
|
||||||
if (address.buildingUnitNo) parts.push(`Ap. ${address.buildingUnitNo}`);
|
if (address.buildingUnitNo) parts.push(`Ap. ${address.buildingUnitNo}`);
|
||||||
if (address.buildingSectionNo) parts.push(`Bl. ${address.buildingSectionNo}`);
|
|
||||||
|
|
||||||
// Locality
|
// Locality
|
||||||
const localityName =
|
const localityName =
|
||||||
@@ -150,7 +150,30 @@ function formatAddress(item?: any) {
|
|||||||
: (address.county?.name ?? "");
|
: (address.county?.name ?? "");
|
||||||
if (countyName) parts.push(`Jud. ${countyName}`);
|
if (countyName) parts.push(`Jud. ${countyName}`);
|
||||||
|
|
||||||
return parts.length ? parts.join(", ") : "";
|
// Postal code
|
||||||
|
if (address.postalCode) parts.push(`Cod ${address.postalCode}`);
|
||||||
|
|
||||||
|
if (parts.length > 0) {
|
||||||
|
formatted.push(parts.join(", "));
|
||||||
|
} else if (address.addressDescription) {
|
||||||
|
// Fall back to description only if no structured fields found
|
||||||
|
const desc = String(address.addressDescription).trim();
|
||||||
|
if (desc.length > 2 && !desc.includes("[object")) {
|
||||||
|
formatted.push(desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we still have nothing, try addressDescription from first entry
|
||||||
|
if (formatted.length === 0) {
|
||||||
|
const desc = addresses[0]?.address?.addressDescription ?? addresses[0]?.addressDescription;
|
||||||
|
if (desc) {
|
||||||
|
const s = String(desc).trim();
|
||||||
|
if (s.length > 2 && !s.includes("[object")) return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...new Set(formatted)].join(" | ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
|||||||
Reference in New Issue
Block a user