SPB Git

Repository Public

route.ts 2.9 KB 83 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/app/api/estimate/route.ts9 * Module           : app10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-08-0912 * Last Modified    : 2026-08-2613 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { NextRequest, NextResponse } from "next/server";43import { estimateByUnitId, estimateManual } from "@/lib/estimator";4445// GET ?id= : estimation d'une unité (contrat historique de l'app iOS 1.x ;46// la v2 préfère GET /api/units/{id}). POST : estimation manuelle.47export function GET(req: NextRequest) {48  const id = req.nextUrl.searchParams.get("id");49  if (!id) return NextResponse.json({ error: "id requis" }, { status: 400 });50  const r = estimateByUnitId(id);51  if (!r) return NextResponse.json({ error: "unité introuvable" }, { status: 404 });52  return NextResponse.json(r);53}5455export async function POST(req: NextRequest) {56  const body = (await req.json()) as {57    municipality?: string;58    typeProp?: string;59    floorArea?: number;60    yearBuilt?: number;61    landArea?: number;62  };63  if (!body.municipality || !body.typeProp) {64    return NextResponse.json(65      { error: "municipality et typeProp requis" },66      { status: 400 }67    );68  }69  const r = estimateManual({70    municipality: body.municipality,71    typeProp: body.typeProp,72    floorArea: body.floorArea,73    yearBuilt: body.yearBuilt,74    landArea: body.landArea,75  });76  if (!r)77    return NextResponse.json(78      { error: "municipalité introuvable ou marché insuffisant" },79      { status: 404 }80    );81  return NextResponse.json(r);82}83
Files main
Menu

Theme