mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-12 01:36:43 +02:00
fix: extractList includes API-specific wrapper keys, diag uses real codefou
- extractList now explicitly checks "mouvements", "articles", "fournisseurs", "ventes", "stocks", "commandes" wrapper keys before generic array fallback - Diag endpoint auto-fetches first real codefou from fournisseurs instead of hardcoded "AUXENCE" (which was supplier nom, not actual codefou) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
9e500b6650
commit
c33e22f7eb
2 files changed
+13
-2
No files matched your search
@@ -30,13 +30,24 @@ async function probe(url: string) {
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const codefou = searchParams.get("codefou") ?? "AUXENCE";
|
||||
|
||||
// Date range: 12 derniers mois
|
||||
const now = new Date();
|
||||
const dateFin = new Date(now.getFullYear(), now.getMonth(), 0).toISOString().slice(0, 10);
|
||||
const dateDebut = new Date(now.getFullYear(), now.getMonth() - 12, 1).toISOString().slice(0, 10);
|
||||
|
||||
// Récupérer le premier codefou réel depuis l'API (si pas fourni en param)
|
||||
let codefou = searchParams.get("codefou");
|
||||
if (!codefou) {
|
||||
try {
|
||||
const res = await fetch(`${FF_API_BASE}/api/fournisseurs?limit=1`, { cache: "no-store" });
|
||||
const data = await res.json();
|
||||
const list = Array.isArray(data) ? data : (Object.values(data).find(v => Array.isArray(v)) as unknown[] ?? []);
|
||||
if (list.length > 0) codefou = (list[0] as Record<string, unknown>).codefou as string ?? null;
|
||||
} catch { /* ignore */ }
|
||||
codefou ??= "D001";
|
||||
}
|
||||
|
||||
const [
|
||||
fournisseurs,
|
||||
articles,
|
||||
|
||||
@@ -85,7 +85,7 @@ function extractList(data: unknown): any[] {
|
||||
if (Array.isArray(data)) return data;
|
||||
const d = data as Record<string, unknown>;
|
||||
// Essaie les wrappers courants
|
||||
for (const key of ["items", "data", "result", "results", "records", "list"]) {
|
||||
for (const key of ["items", "data", "result", "results", "records", "list", "mouvements", "articles", "fournisseurs", "ventes", "stocks", "commandes"]) {
|
||||
if (Array.isArray(d[key])) return d[key] as unknown[];
|
||||
}
|
||||
// Cherche la première propriété qui est un tableau
|
||||
|
||||
Reference in new issue
Block a user