mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-21 22:18:08 +02:00
feat: introduce PostgreSQL client module to replace per-article HTTP requests with bulk SQL queries
This commit is contained in:
1 parent
c7d5bbe3b1
commit
038e87f554
1 file changed
+33
-9
+33
-9
@@ -633,16 +633,40 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
|
|||||||
}
|
}
|
||||||
const refData = await refRes.json();
|
const refData = await refRes.json();
|
||||||
|
|
||||||
// --- Supplier: pick fournisseur with preference=1 (true main supplier, not depot) ---
|
// --- Supplier: exclude known depot platform codes, pick best real supplier ---
|
||||||
let fou = article.nom_fou_principal || article.codefou_principal || 'Sans fournisseur';
|
type FouEntry = { codefou: string; nom_fou: string | null; preference: number | null; suspendu: string | null };
|
||||||
|
let fou = '—';
|
||||||
|
|
||||||
|
// Known depot/platform codes that are NOT real commercial suppliers
|
||||||
|
const DEPOT_CODES = new Set(['D005', 'B0071', 'D005 ', 'B0071 ']);
|
||||||
|
|
||||||
if (refData.fournisseurs && Array.isArray(refData.fournisseurs)) {
|
if (refData.fournisseurs && Array.isArray(refData.fournisseurs)) {
|
||||||
// preference=1 means the main declared supplier
|
const fous = refData.fournisseurs as FouEntry[];
|
||||||
const mainFou = (refData.fournisseurs as { codefou: string; nom_fou: string | null; preference: number }[])
|
|
||||||
.find(f => f.preference === 1);
|
const pickLabel = (f: FouEntry): string => f.nom_fou?.trim() || f.codefou.trim();
|
||||||
if (mainFou?.nom_fou) {
|
|
||||||
fou = mainFou.nom_fou;
|
// Epoch sentinel 1901 = never actually suspended in this system
|
||||||
} else if (mainFou?.codefou) {
|
const isActive = (f: FouEntry): boolean =>
|
||||||
fou = mainFou.codefou;
|
!f.suspendu || f.suspendu.startsWith('1901');
|
||||||
|
|
||||||
|
// Filter out known depot platform codes only (not all D* codes — DART FRANCE etc. are real suppliers)
|
||||||
|
const realFous = fous.filter(f => !DEPOT_CODES.has(f.codefou.trim()));
|
||||||
|
|
||||||
|
if (realFous.length > 0) {
|
||||||
|
// Priority 1: preference=1 AND active
|
||||||
|
const p1Active = realFous.find(f => f.preference === 1 && isActive(f));
|
||||||
|
// Priority 2: preference=1 (even if suspended — at least declared as main)
|
||||||
|
const p1Any = realFous.find(f => f.preference === 1);
|
||||||
|
// Priority 3: any active non-depot supplier
|
||||||
|
const anyActive = realFous.find(f => isActive(f));
|
||||||
|
// Priority 4: first non-depot (last resort)
|
||||||
|
const first = realFous[0];
|
||||||
|
|
||||||
|
const best = p1Active ?? p1Any ?? anyActive ?? first;
|
||||||
|
fou = pickLabel(best);
|
||||||
|
} else {
|
||||||
|
// Only depot codes found — this article is sourced through the depot platform
|
||||||
|
fou = 'Dépôt';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fouMap.set(codein, fou);
|
fouMap.set(codein, fou);
|
||||||
|
|||||||
Reference in new issue
Block a user