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
+61
View File
@@ -0,0 +1,61 @@
/**
* GET /api/geoportal/cf-status?nrCad=...
*
* Checks if a CF extract exists for a given cadastral number.
* Returns download info if available.
*/
import { NextResponse } from "next/server";
import { prisma } from "@/core/storage/prisma";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function GET(req: Request) {
const url = new URL(req.url);
const nrCad = url.searchParams.get("nrCad")?.trim();
if (!nrCad) {
return NextResponse.json({ error: "nrCad obligatoriu" }, { status: 400 });
}
try {
// Find the latest completed CF extract for this cadastral number
const extract = await prisma.cfExtract.findFirst({
where: {
nrCadastral: nrCad,
status: "completed",
minioPath: { not: "" },
},
orderBy: { completedAt: "desc" },
select: {
id: true,
nrCadastral: true,
nrCF: true,
status: true,
minioPath: true,
documentName: true,
completedAt: true,
expiresAt: true,
},
});
if (!extract || !extract.minioPath) {
return NextResponse.json({ available: false });
}
const expired = extract.expiresAt && new Date(extract.expiresAt) < new Date();
return NextResponse.json({
available: !expired,
expired: !!expired,
id: extract.id,
nrCF: extract.nrCF,
documentName: extract.documentName,
completedAt: extract.completedAt?.toISOString(),
downloadUrl: `/api/ancpi/download?id=${extract.id}`,
});
} catch (error) {
const msg = error instanceof Error ? error.message : "Eroare";
return NextResponse.json({ error: msg }, { status: 500 });
}
}
+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 });
}
}