Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Vrai-Prix8 * File : src/app/api/avendre/route.ts9 * Module : app10 * Repository : https://git.spboucher.ai/vrai-prix11 * Created : 2026-09-0812 * Last Modified : 2026-09-0813 *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 dans les propriétés à vendre (copie des annonces + estimations vp_eval).44import { NextRequest, NextResponse } from "next/server";45import { searchListings, type SortKey, type TypeGroupKey } from "@/lib/immoka";4647export const dynamic = "force-dynamic";4849const SORTS: SortKey[] = ["recent", "price_asc", "price_desc", "deal", "premium", "est_desc"];50const GROUPS: TypeGroupKey[] = ["maison", "condo", "plex", "terrain", "chalet", "fermette", "mobile", "commercial", "autre"];5152export function GET(req: NextRequest) {53 const q = req.nextUrl.searchParams;54 const num = (k: string) => {55 const v = Number(q.get(k));56 return Number.isFinite(v) && v > 0 ? v : undefined;57 };58 const sort = q.get("sort") as SortKey | null;59 const group = q.get("group") as TypeGroupKey | null;60 try {61 const res = searchListings({62 q: q.get("q") ?? undefined,63 muni: q.get("muni") ?? undefined,64 group: group && GROUPS.includes(group) ? group : "",65 min: num("min"),66 max: num("max"),67 beds: num("beds"),68 evalOnly: q.get("eval") === "1",69 fiable: q.get("fiab") === "1",70 sort: sort && SORTS.includes(sort) ? sort : "recent",71 page: num("page") ?? 1,72 per: num("per") ?? 24,73 });74 return NextResponse.json(res, {75 headers: { "Cache-Control": "public, max-age=120, stale-while-revalidate=600" },76 });77 } catch (e) {78 return NextResponse.json({ error: String(e) }, { status: 500 });79 }80}81