SPB Git

Repository Public

route.ts 2.6 KB 68 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/app/api/search/route.ts9 * Module           : app10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-08-0912 * Last Modified    : 2026-08-0913 *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 { searchUnits } from "@/lib/db";4445// GET /api/search?q=…[&limit=8] — autocomplétion d'adresse (FTS5, préfixes).46// Au moins 3 caractères. Champs historiques (id, adresse, apt, municipalite,47// typeProp) conservés pour l'app iOS 1.x ; lat, lng et est2026 ajoutés.48export function GET(req: NextRequest) {49  const q = req.nextUrl.searchParams.get("q") ?? "";50  if (q.trim().length < 3) return NextResponse.json({ results: [] });51  const limit = Math.min(20, Math.max(1, Number(req.nextUrl.searchParams.get("limit")) || 8));52  try {53    const results = searchUnits(q, limit).map((u) => ({54      id: u.id_provinc,55      adresse: u.adresse,56      apt: u.apt,57      municipalite: u.municipalite,58      typeProp: u.type_prop,59      lat: u.lat,60      lng: u.lng,61      est2026: u.est_2026,62    }));63    return NextResponse.json({ results }, { headers: { "Cache-Control": "public, max-age=300" } });64  } catch {65    return NextResponse.json({ results: [] });66  }67}68
Files main
Menu

Theme