diff --git a/src/app/api/geoportal/setup-enrichment-views/route.ts b/src/app/api/geoportal/setup-enrichment-views/route.ts index 5c4ebd5..f18b946 100644 --- a/src/app/api/geoportal/setup-enrichment-views/route.ts +++ b/src/app/api/geoportal/setup-enrichment-views/route.ts @@ -47,14 +47,18 @@ const VIEWS = [ f."cadastralRef" AS cadastral_ref, f."areaValue" AS area_value, f."isActive" AS is_active, - COALESCE((p.enrichment->>'BUILD_LEGAL')::int, -1) AS build_legal, + COALESCE( + (SELECT (p.enrichment->>'BUILD_LEGAL')::int + FROM "GisFeature" p + WHERE p.siruta = f.siruta + AND p."cadastralRef" = f."cadastralRef" + AND (p."layerId" LIKE 'TERENURI%' OR p."layerId" LIKE 'CADGEN_LAND%') + AND p.enrichment IS NOT NULL + LIMIT 1), + -1 + ) AS build_legal, f.geom FROM "GisFeature" f - LEFT JOIN "GisFeature" p - ON p.siruta = f.siruta - AND p."cadastralRef" = f."cadastralRef" - AND (p."layerId" LIKE 'TERENURI%' OR p."layerId" LIKE 'CADGEN_LAND%') - AND p.enrichment IS NOT NULL WHERE f.geom IS NOT NULL AND (f."layerId" LIKE 'CLADIRI%' OR f."layerId" LIKE 'CADGEN_BUILDING%')`, },