Repository Public
1// Vrai-Prix — méthode du coût : préremplissage d'une propriété du rôle (MAMH) + autres lectures de la valeur.2import { NextRequest, NextResponse } from "next/server";3import { otherReadingsForProperty, prefillFromProperty, recentEstimatesForProperty } from "@/lib/cost/estimate";4import { resolveLocation } from "@/lib/cost/catalog";56export const runtime = "nodejs";78export function GET(req: NextRequest) {9 const raw = req.nextUrl.searchParams.get("id");10 if (!raw) return NextResponse.json({ error: "id requis" }, { status: 400 });11 const id = raw.replace(/\D/g, "") || raw;12 try {13 const p = prefillFromProperty(id);14 if (!p) return NextResponse.json({ error: "propriété introuvable" }, { status: 404 });15 const loc = resolveLocation({ municipality: p.input.municipality, lat: p.input.lat, lng: p.input.lng });16 const readings = req.nextUrl.searchParams.get("readings") === "0" ? null : otherReadingsForProperty(id);17 return NextResponse.json({ ...p, location: loc.location, locationMethod: loc.method, otherReadings: readings, recent: recentEstimatesForProperty(id) });18 } catch (e) {19 return NextResponse.json({ error: (e as Error).message }, { status: 500 });20 }21}22