fix(parcel-sync): robust workspace resolution with direct nomen lookup

- Add fetchNomenByPk() to EterraClient  single nomen entry lookup
- resolveWorkspace() now tries fast path first: direct nomen lookup for
  SIRUTA  walk parentNomenPk chain to find COUNTY (1-3 calls vs 42+)
- Falls back to full county scan only if direct lookup fails
- Search route: DB lookup as middle fallback between workspacePk and resolve
- Debug logging to trace workspace resolution on production
- Fix: try all possible UAT identifier fields (nomenPk, siruta, code, pk)
This commit is contained in:
AI Assistant
2026-03-06 21:09:22 +02:00
parent ec5a866673
commit 1b72d641cd
3 changed files with 118 additions and 38 deletions
@@ -328,21 +328,17 @@ export function ParcelSyncModule() {
// Load UATs from local DB (fast — no eTerra needed)
fetch("/api/eterra/uats")
.then((res) => res.json())
.then(
(data: {
uats?: UatEntry[];
}) => {
if (data.uats && data.uats.length > 0) {
setUatData(data.uats);
} else {
// DB empty — fall back to static uat.json (no county/workspace)
fetch("/uat.json")
.then((res) => res.json())
.then((fallback: UatEntry[]) => setUatData(fallback))
.catch(() => {});
}
},
)
.then((data: { uats?: UatEntry[] }) => {
if (data.uats && data.uats.length > 0) {
setUatData(data.uats);
} else {
// DB empty — fall back to static uat.json (no county/workspace)
fetch("/uat.json")
.then((res) => res.json())
.then((fallback: UatEntry[]) => setUatData(fallback))
.catch(() => {});
}
})
.catch(() => {
// API failed — fall back to static uat.json
fetch("/uat.json")
@@ -372,23 +368,19 @@ export function ParcelSyncModule() {
// POST triggers sync check — only does full fetch if data changed
fetch("/api/eterra/uats", { method: "POST" })
.then((res) => res.json())
.then(
(data: { synced?: boolean }) => {
if (data.synced) {
// Data changed — reload from DB
fetch("/api/eterra/uats")
.then((res) => res.json())
.then(
(fresh: { uats?: UatEntry[] }) => {
if (fresh.uats && fresh.uats.length > 0) {
setUatData(fresh.uats);
}
},
)
.catch(() => {});
}
},
)
.then((data: { synced?: boolean }) => {
if (data.synced) {
// Data changed — reload from DB
fetch("/api/eterra/uats")
.then((res) => res.json())
.then((fresh: { uats?: UatEntry[] }) => {
if (fresh.uats && fresh.uats.length > 0) {
setUatData(fresh.uats);
}
})
.catch(() => {});
}
})
.catch(() => {});
}, [session.connected]);