import { NextResponse } from "next/server"; import { getAuthSession } from "@/core/auth/require-auth"; import { gisApi, GisApiError, type ParcelRefBody } from "@/lib/gis-api-client"; export const runtime = "nodejs"; export const dynamic = "force-dynamic"; export async function POST(request: Request) { const session = await getAuthSession(); if (!session) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } let body: ParcelRefBody; try { body = (await request.json()) as ParcelRefBody; } catch { return NextResponse.json({ error: "invalid_body" }, { status: 400 }); } if (!body?.siruta || !body?.cadastralRef) { return NextResponse.json( { error: "missing_fields", required: ["siruta", "cadastralRef"] }, { status: 400 }, ); } try { const data = await gisApi.parcel.tech(body); return NextResponse.json(data); } catch (err) { if (err instanceof GisApiError) { return NextResponse.json( { error: err.code, status: err.status, body: err.body }, { status: err.status }, ); } return NextResponse.json({ error: "internal_error" }, { status: 500 }); } }