fix(parcel-sync): fix [object Object] in address field + re-enrich corrupted
The eTerra API returns street and locality as objects ({name: "..."})
not strings. formatAddress now extracts .name correctly.
Also added:
- streetNumber fallback (alongside buildingNo)
- String() safety on addressDescription
- Corruption check: any enrichment containing "[object Object]" is
automatically re-enriched on next cycle
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -99,10 +99,21 @@ const formatAddress = (item?: any) => {
|
|||||||
const address = item?.immovableAddresses?.[0]?.address ?? null;
|
const address = item?.immovableAddresses?.[0]?.address ?? null;
|
||||||
if (!address) return "-";
|
if (!address) return "-";
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
if (address.addressDescription) parts.push(address.addressDescription);
|
if (address.addressDescription) parts.push(String(address.addressDescription));
|
||||||
if (address.street) parts.push(`Str. ${address.street}`);
|
// street can be a string or an object { name: "..." }
|
||||||
if (address.buildingNo) parts.push(`Nr. ${address.buildingNo}`);
|
const streetName =
|
||||||
if (address.locality?.name) parts.push(address.locality.name);
|
typeof address.street === "string"
|
||||||
|
? address.street
|
||||||
|
: address.street?.name ?? null;
|
||||||
|
if (streetName) parts.push(`Str. ${streetName}`);
|
||||||
|
if (address.streetNumber) parts.push(`Nr. ${address.streetNumber}`);
|
||||||
|
else if (address.buildingNo) parts.push(`Nr. ${address.buildingNo}`);
|
||||||
|
// locality can be a string or an object { name: "..." }
|
||||||
|
const localityName =
|
||||||
|
typeof address.locality === "string"
|
||||||
|
? address.locality
|
||||||
|
: address.locality?.name ?? null;
|
||||||
|
if (localityName) parts.push(localityName);
|
||||||
return parts.length ? parts.join(", ") : "-";
|
return parts.length ? parts.join(", ") : "-";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -439,11 +450,18 @@ export async function enrichFeatures(
|
|||||||
enrichJson[k] !== "",
|
enrichJson[k] !== "",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Corruption check: re-enrich if any field contains "[object Object]"
|
||||||
|
const hasCorruptedValues =
|
||||||
|
enrichJson != null &&
|
||||||
|
Object.values(enrichJson).some(
|
||||||
|
(v) => typeof v === "string" && v.includes("[object Object]"),
|
||||||
|
);
|
||||||
|
|
||||||
// Age check: re-enrich if older than 30 days (catches eTerra updates)
|
// Age check: re-enrich if older than 30 days (catches eTerra updates)
|
||||||
const ageMs = Date.now() - new Date(feature.enrichedAt).getTime();
|
const ageMs = Date.now() - new Date(feature.enrichedAt).getTime();
|
||||||
const isTooOld = ageMs > 30 * 24 * 60 * 60 * 1000;
|
const isTooOld = ageMs > 30 * 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
if (structurallyComplete && hasRealValues && !isTooOld) {
|
if (structurallyComplete && hasRealValues && !isTooOld && !hasCorruptedValues) {
|
||||||
enrichedCount += 1;
|
enrichedCount += 1;
|
||||||
if (index % 50 === 0) {
|
if (index % 50 === 0) {
|
||||||
options?.onProgress?.(
|
options?.onProgress?.(
|
||||||
|
|||||||
Reference in New Issue
Block a user