feat(geoportal): enrichment API + CF download + bulk enrichment

New API endpoints:
- POST /api/geoportal/enrich — enriches all parcels for a SIRUTA,
  skips already-enriched, persists in GisFeature.enrichment column
- GET /api/geoportal/cf-status?nrCad=... — checks if CF extract exists,
  returns download URL if available

Feature panel:
- No enrichment: "Enrichment" button (triggers eTerra sync for UAT)
- Has enrichment + CF available: "Descarca CF" button (direct download)
- Has enrichment + no CF: "Comanda CF" button (link to ePay tab)
- Copy button always visible
- After enrichment completes, panel auto-reloads data

Selection toolbar:
- Bulk "Enrichment" button for selected parcels (per unique SIRUTA)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-24 10:48:08 +02:00
parent 800c45916e
commit c4122cea01
4 changed files with 217 additions and 55 deletions
+54
View File
@@ -0,0 +1,54 @@
/**
* POST /api/geoportal/enrich
*
* Enriches parcels for a given SIRUTA. Skips already-enriched features.
* Uses existing eTerra session or env credentials.
* Enrichment data is PERSISTED in GisFeature.enrichment column.
*
* Body: { siruta: string } or { ids: string[] } (feature UUIDs)
*/
import { NextResponse } from "next/server";
import { EterraClient } from "@/modules/parcel-sync/services/eterra-client";
import { enrichFeatures } from "@/modules/parcel-sync/services/enrich-service";
import { getSessionCredentials } from "@/modules/parcel-sync/services/session-store";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function POST(req: Request) {
try {
const body = (await req.json()) as { siruta?: string };
const siruta = String(body.siruta ?? "").trim();
if (!siruta) {
return NextResponse.json({ error: "SIRUTA obligatoriu" }, { status: 400 });
}
// Get credentials: session first, then env
const session = getSessionCredentials();
const username = session?.username || process.env.ETERRA_USERNAME || "";
const password = session?.password || process.env.ETERRA_PASSWORD || "";
if (!username || !password) {
return NextResponse.json(
{ error: "Credentiale eTerra lipsa. Logheaza-te in eTerra Parcele mai intai." },
{ status: 401 }
);
}
const client = await EterraClient.create(username, password);
const result = await enrichFeatures(client, siruta);
return NextResponse.json({
status: result.status,
enrichedCount: result.enrichedCount,
buildingCrossRefs: result.buildingCrossRefs,
message: result.enrichedCount > 0
? `${result.enrichedCount} parcele imbogatite cu succes`
: "Toate parcelele au deja date de enrichment",
});
} catch (error) {
const msg = error instanceof Error ? error.message : "Eroare la enrichment";
return NextResponse.json({ error: msg }, { status: 500 });
}
}