SPB Git

Repository Public

route.ts 3.1 KB 81 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/app/api/nearby/route.ts9 * Module           : app10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-08-1112 * Last Modified    : 2026-08-1313 *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 */4142// Auteur : Simon-Pierre Boucher — contact@spboucher.ai43// Recherche par carte : unités d'évaluation autour d'un point (boîte englobante).44// Le rayon est plafonné côté serveur — la carte doit être assez zoomée.45import { NextRequest, NextResponse } from "next/server";46import { unitsNear } from "@/lib/db";4748// Plafonds relevés pour la carte : les valeurs par défaut49// restent inchangées — l'app iOS 1.1.0 en place reçoit exactement le même50// contrat (changement additif ; ses gouttières disparaissent même).51const MAX_HALF_LAT = 0.08; // ~8,9 km52const MAX_HALF_LNG = 0.12;53const MAX_LIMIT = 1500;5455export function GET(req: NextRequest) {56  const q = req.nextUrl.searchParams;57  const lat = Number(q.get("lat"));58  const lng = Number(q.get("lng"));59  if (!Number.isFinite(lat) || !Number.isFinite(lng)) {60    return NextResponse.json({ error: "lat et lng requis" }, { status: 400 });61  }62  const halfLat = Math.min(Math.abs(Number(q.get("halfLat")) || 0.008), MAX_HALF_LAT);63  const halfLng = Math.min(Math.abs(Number(q.get("halfLng")) || 0.012), MAX_HALF_LNG);64  const limit = Math.min(Math.abs(Number(q.get("limit")) || 300), MAX_LIMIT);65  try {66    const results = unitsNear(lat, lng, halfLat, halfLng, limit).map((u) => ({67      id: u.id_provinc,68      adresse: u.adresse,69      apt: u.apt,70      municipalite: u.municipalite,71      typeProp: u.type_prop,72      lat: u.lat,73      lng: u.lng,74      est2026: u.est_2026,75    }));76    return NextResponse.json({ results });77  } catch {78    return NextResponse.json({ results: [] });79  }80}81
Files main
Menu

Theme