fix(parcel-sync): restore SIRUTA in dropdown, add county debug output
- Restore SIRUTA code display in parentheses next to UAT name - PATCH response now includes debug samples (sampleUat keys, county raw data) visible in browser console for diagnosing matching issues - POST endpoint now supports resync (upsert mode, safe to call again) - Client logs full PATCH result to browser console for debugging Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -165,7 +165,9 @@ export async function GET() {
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* POST /api/eterra/uats */
|
||||
/* */
|
||||
/* Seed DB from static uat.json. */
|
||||
/* Seed or resync DB from static uat.json. */
|
||||
/* Uses upsert so it's safe to call repeatedly — new UATs are added, */
|
||||
/* existing names are updated, county/workspacePk are preserved. */
|
||||
/* eTerra nomenPk ≠ SIRUTA, so we cannot use the nomenclature API */
|
||||
/* for populating UAT data. uat.json has correct SIRUTA codes. */
|
||||
/* Workspace (county) PKs are resolved lazily via ArcGIS layer query */
|
||||
@@ -174,15 +176,6 @@ export async function GET() {
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
// Check if DB already has data
|
||||
const dbCount = await prisma.gisUat.count();
|
||||
if (dbCount > 0) {
|
||||
return NextResponse.json({
|
||||
synced: false,
|
||||
reason: "already-seeded",
|
||||
total: dbCount,
|
||||
});
|
||||
}
|
||||
|
||||
// Read uat.json from public/ directory
|
||||
let rawUats: Array<{ siruta: string; name: string }>;
|
||||
@@ -368,6 +361,11 @@ export async function PATCH() {
|
||||
let nameMatches = 0;
|
||||
const matchedSirutas = new Set<string>();
|
||||
let loggedSample = false;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let sampleCounty: any = null;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let sampleUat: any = null;
|
||||
let totalEterraUats = 0;
|
||||
|
||||
for (const [countyPk, countyName] of countyMap) {
|
||||
if (matchedSirutas.size >= needsCounty.length) break;
|
||||
@@ -376,12 +374,20 @@ export async function PATCH() {
|
||||
const rawUats = await client.fetchAdminUnitsByCounty(countyPk);
|
||||
const uats = unwrapArray(rawUats);
|
||||
|
||||
totalEterraUats += uats.length;
|
||||
|
||||
// Log first county's first UAT for debugging
|
||||
if (!loggedSample && uats.length > 0) {
|
||||
sampleUat = uats[0];
|
||||
sampleCounty = { pk: countyPk, name: countyName, uatCount: uats.length };
|
||||
console.log(
|
||||
`[uats-patch] Sample UAT from ${countyName}:`,
|
||||
`[uats-patch] Sample UAT from ${countyName} (${uats.length} UATs):`,
|
||||
JSON.stringify(uats[0]).slice(0, 500),
|
||||
);
|
||||
console.log(
|
||||
`[uats-patch] Sample UAT keys:`,
|
||||
Object.keys(uats[0] ?? {}),
|
||||
);
|
||||
loggedSample = true;
|
||||
}
|
||||
|
||||
@@ -444,7 +450,23 @@ export async function PATCH() {
|
||||
codeMatches,
|
||||
nameMatches,
|
||||
totalCounties: countyMap.size,
|
||||
totalEterraUats,
|
||||
unmatched,
|
||||
// Include debug samples so we can see what eTerra returns
|
||||
debug: {
|
||||
sampleCounty,
|
||||
sampleUatKeys: sampleUat ? Object.keys(sampleUat) : null,
|
||||
sampleUat: sampleUat
|
||||
? JSON.parse(JSON.stringify(sampleUat).slice(0, 500))
|
||||
: null,
|
||||
sampleCountyRaw: counties[0]
|
||||
? {
|
||||
keys: Object.keys(counties[0]),
|
||||
nomenPk: counties[0].nomenPk,
|
||||
name: counties[0].name,
|
||||
}
|
||||
: null,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Eroare server";
|
||||
|
||||
Reference in New Issue
Block a user