From 910b0c96ef70737441813c5ddd048eb517544a8f Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Wed, 8 Apr 2026 16:41:28 +0200 Subject: [PATCH] feat: add PostgreSQL client for bulk data retrieval and configure Claude permissions --- .claude/settings.json | 3 ++- src/lib/pg-ff-client.ts | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.claude/settings.json b/.claude/settings.json index 6458876..4d5d390 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -31,7 +31,8 @@ "Read(//c/Users/Michael/VSCODE/CollectFlow/**)", "Bash(xargs wc:*)", "Bash(ls /c/Users/Michael/VSCODE/CollectFlow/.next/static/chunks/*.css)", - "Bash(find /c/Users/Michael/VSCODE/CollectFlow/src/app/api -type f \\\\\\( -name \"*.ts\" -o -name \"*.tsx\" \\\\\\) -exec ls -lh {} \\\\;)" + "Bash(find /c/Users/Michael/VSCODE/CollectFlow/src/app/api -type f \\\\\\( -name \"*.ts\" -o -name \"*.tsx\" \\\\\\) -exec ls -lh {} \\\\;)", + "Bash(curl -s \"https://api.ffnancy.fr/api/commandes-auto\")" ] } } diff --git a/src/lib/pg-ff-client.ts b/src/lib/pg-ff-client.ts index f9a5cbd..9b1ee8f 100644 --- a/src/lib/pg-ff-client.ts +++ b/src/lib/pg-ff-client.ts @@ -946,23 +946,24 @@ export async function pgGetCommandesAuto(): Promise { if (!res.ok) throw new Error(`HTTP ${res.status}`); const data = await res.json(); // L'API peut retourner directement un tableau ou un objet wrappé + // L'API retourne { count: N, propositions: [...] } const rows: unknown[] = Array.isArray(data) ? data - : (data?.data ?? data?.items ?? data?.results ?? []); + : (data?.propositions ?? data?.data ?? data?.items ?? data?.results ?? []); console.log(`[pg-ff] pgGetCommandesAuto: ${rows.length} lignes (API Hostinger)`); - // Normalise chaque ligne vers PgCommandeAutoRow // eslint-disable-next-line @typescript-eslint/no-explicit-any return (rows as any[]).map((r): PgCommandeAutoRow => ({ - site: String(r.site ?? r.Site ?? ""), - codefou: String(r.codefou ?? r.CodeFou ?? r.code ?? ""), - nomfou: String(r.nomfou ?? r.NomFou ?? r.nom ?? ""), - franco: Number(r.franco ?? r.Franco ?? 0), - nb_articles: Number(r.nb_articles ?? r.nbArticles ?? r.count ?? 0), - montant_cde: Number(r.montant_cde ?? r.montantCde ?? r.montant ?? 0), - franco_atteint: r.franco_atteint != null - ? Boolean(r.franco_atteint) - : null, - ecart_franco: Number(r.ecart_franco ?? r.ecartFranco ?? 0), + site: String(r.site ?? ""), + codefou: String(r.codefou ?? ""), + nomfou: String(r.nom_fou ?? r.nomfou ?? ""), + franco: Number(r.franco_ht ?? r.franco ?? 0), + nb_articles: Number(r.nb_articles ?? 0), + montant_cde: Number(r.montant_propo_ht ?? r.montant_cde ?? 0), + franco_atteint: r.franco_atteint === "OUI" ? true + : r.franco_atteint === "NON" ? false + : r.franco_atteint != null ? Boolean(r.franco_atteint) + : null, + ecart_franco: Number(r.ecart_franco ?? 0), })); } catch (e) { console.error("[pg-ff] pgGetCommandesAuto error:", (e as Error).message?.slice(0, 300));