Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Vrai-Prix8 * File : src/app/api/admin/cost/benchmarks/import/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// Vrai-Prix — admin méthode du coût : import manuel de benchmarks (Altus) ou de prix licenciés (RSMeans).43// Corps : { kind: "benchmarks" | "rsmeans", data: <CSV texte | tableau JSON> }44import { NextRequest, NextResponse } from "next/server";45import { adminAuth } from "@/lib/cost/connectors/admin";46import { importBenchmarks, importRsmeans } from "@/lib/cost/connectors/imports";47import { invalidateCache } from "@/lib/cost/cache";48import { metaSet } from "@/lib/cost/db";4950export const runtime = "nodejs";5152export async function POST(req: NextRequest) {53 const denied = adminAuth(req);54 if (denied) return denied;55 let b: { kind?: string; data?: unknown };56 const ct = req.headers.get("content-type") ?? "";57 try {58 if (ct.includes("text/csv") || ct.includes("text/plain")) b = { kind: req.nextUrl.searchParams.get("kind") ?? "benchmarks", data: await req.text() };59 else b = await req.json();60 } catch { return NextResponse.json({ error: "corps invalide (JSON ou CSV)" }, { status: 400 }); }61 try {62 const r = b.kind === "rsmeans" ? importRsmeans(b.data) : importBenchmarks(b.data);63 if (r.imported) { metaSet("last_ingest", new Date().toISOString()); invalidateCache(); }64 return NextResponse.json({ kind: b.kind ?? "benchmarks", ...r });65 } catch (e) {66 return NextResponse.json({ error: (e as Error).message }, { status: 500 });67 }68}69