Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Vrai-Prix8 * File : src/app/api/stats/report/custom/route.ts9 * Module : app10 * Repository : https://git.spboucher.ai/vrai-prix11 * Created : 2026-08-2312 * Last Modified : 2026-08-2313 *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/**43 * POST /api/stats/report/custom — v3 : rapport PDF personnalisé. Corps : {"title", "period", "from", "to",44 * "blocks": [{"key": "series:…", "render": "bar"}, …]} — ordre respecté,45 * clés inconnues ignorées, aucune clé valide → 400.46 */47import { type NextRequest, NextResponse } from "next/server";48import { buildCustomReport, reportFilename, type CustomSpec } from "@/lib/report-stats";4950export async function POST(req: NextRequest) {51 let spec: CustomSpec;52 try {53 spec = (await req.json()) as CustomSpec;54 } catch {55 return NextResponse.json({ error: "Corps JSON invalide" }, { status: 400 });56 }57 try {58 const pdf = await buildCustomReport(spec ?? {});59 return new NextResponse(new Uint8Array(pdf), {60 headers: {61 "Content-Type": "application/pdf",62 "Content-Disposition": `attachment; filename="${reportFilename("personnalise")}"`,63 },64 });65 } catch (e) {66 if (e instanceof Error && e.message === "aucun-bloc") {67 return NextResponse.json({ error: "Aucun bloc valide dans la composition" }, { status: 400 });68 }69 throw e;70 }71}72