Repository Public
1// Auteur : Simon-Pierre Boucher — contact@spboucher.ai2/**3 * GET /api/stats/report?mode=complet|synthese|tendances|repartitions|donnees4 * — rapport statistique PDF au gabarit commun Groupe KA v2 (src/ka/stats/5 * SPEC.md §3), moteur pdfkit vectoriel. Un mode inconnu retombe sur6 * « complet ». `period`/`from`/`to` sont acceptés (contrat commun) mais non7 * applicables : les données sont un instantané du rôle 2026.8 * Alias historique : /api/report/stats.9 */10import { type NextRequest, NextResponse } from "next/server";11import { buildStatsReport, reportFilename, REPORT_MODES, type ReportMode } from "@/lib/report-stats";1213export async function GET(req: NextRequest) {14 const raw = req.nextUrl.searchParams.get("mode") ?? "complet";15 const mode: ReportMode = (REPORT_MODES as readonly string[]).includes(raw)16 ? (raw as ReportMode)17 : "complet";18 const pdf = await buildStatsReport(mode);19 return new NextResponse(new Uint8Array(pdf), {20 headers: {21 "Content-Type": "application/pdf",22 "Content-Disposition": `attachment; filename="${reportFilename(mode)}"`,23 "Cache-Control": "public, max-age=3600",24 },25 });26}27