mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-23 15:08:12 +02:00
feat: implement PostgreSQL-based bulk fetching for article and sales data to replace HTTP API calls
This commit is contained in:
1 parent
64da878abb
commit
32c1e06782
3 files changed
+35
-21
No files matched your search
@@ -5,7 +5,12 @@
|
|||||||
"Bash(rtk tsc:*)",
|
"Bash(rtk tsc:*)",
|
||||||
"Bash(rtk grep:*)",
|
"Bash(rtk grep:*)",
|
||||||
"Bash(node_modules/.bin/tsc --noEmit)",
|
"Bash(node_modules/.bin/tsc --noEmit)",
|
||||||
"Bash(./node_modules/.bin/tsc --noEmit)"
|
"Bash(./node_modules/.bin/tsc --noEmit)",
|
||||||
|
"Bash(grep -v \"^$\")",
|
||||||
|
"Bash(rtk git *)",
|
||||||
|
"Bash(rtk npx *)",
|
||||||
|
"Bash(git add *)",
|
||||||
|
"Bash(git commit *)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
async function test() {
|
||||||
|
const res = await fetch("https://api.ffnancy.fr/api/performance/dashboard?date=2024-04-20");
|
||||||
|
const data = await res.json();
|
||||||
|
console.log(JSON.stringify(data.top10_ca?.[0] || {}, null, 2));
|
||||||
|
}
|
||||||
|
test();
|
||||||
+22
-20
@@ -605,25 +605,27 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
|
|||||||
// s'affiche même si la DB n'est pas configurée).
|
// s'affiche même si la DB n'est pas configurée).
|
||||||
let stockMap = new Map<string, { stock292: number; stock579: number; stockTotal: number }>();
|
let stockMap = new Map<string, { stock292: number; stock579: number; stockTotal: number }>();
|
||||||
let fouMap = new Map<string, string>();
|
let fouMap = new Map<string, string>();
|
||||||
try {
|
if (allCodeins.length > 0) {
|
||||||
const [sm, fouResult] = await Promise.all([
|
try {
|
||||||
pgGetStockForCodeins(allCodeins),
|
const [sm, fouResult] = await Promise.all([
|
||||||
pgNoParallel(sql`
|
pgGetStockForCodeins(allCodeins),
|
||||||
SELECT
|
pgNoParallel(sql`
|
||||||
a.codein,
|
SELECT
|
||||||
COALESCE(fi.nom, af.code, 'Sans fournisseur')::text AS fournisseur
|
a.codein::text AS codein,
|
||||||
FROM articles a
|
COALESCE(fi.nom, af.code, 'Sans fournisseur')::text AS fournisseur
|
||||||
LEFT JOIN artfou1 af ON af.art_no_id = a.no_id AND af.preference = 1
|
FROM articles a
|
||||||
LEFT JOIN fouident fi ON fi.code = af.code
|
LEFT JOIN artfou1 af ON af.art_no_id = a.no_id AND af.preference = 1
|
||||||
WHERE a.codein = ANY(string_to_array(${allCodeins.join(",")}, ','))
|
LEFT JOIN fouident fi ON fi.code = af.code
|
||||||
`),
|
WHERE a.codein::text = ANY(string_to_array(${allCodeins.join(",")}, ','))
|
||||||
]);
|
`),
|
||||||
stockMap = sm;
|
]);
|
||||||
for (const row of fouResult.rows as unknown as { codein: string; fournisseur: string }[]) {
|
stockMap = sm;
|
||||||
if (row.codein) fouMap.set(row.codein, row.fournisseur);
|
for (const row of fouResult.rows as unknown as { codein: string; fournisseur: string }[]) {
|
||||||
|
if (row.codein) fouMap.set(row.codein, row.fournisseur);
|
||||||
|
}
|
||||||
|
} catch (enrichErr) {
|
||||||
|
console.warn("[Dashboard] DB enrichment unavailable, continuing with API data only:", enrichErr);
|
||||||
}
|
}
|
||||||
} catch (enrichErr) {
|
|
||||||
console.warn("[Dashboard] DB enrichment unavailable, continuing with API data only:", enrichErr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const siteSet = [...new Set(allItems.map(i => i.site).filter(Boolean))].sort();
|
const siteSet = [...new Set(allItems.map(i => i.site).filter(Boolean))].sort();
|
||||||
@@ -848,10 +850,10 @@ export async function pgGetStockForCodeins(codeins: string[]): Promise<Map<strin
|
|||||||
|
|
||||||
const codeinsStr = codeins.join(",");
|
const codeinsStr = codeins.join(",");
|
||||||
const result = await pgNoParallel(
|
const result = await pgNoParallel(
|
||||||
sql`SELECT a.codein, cs.site, cs.stockdispo::float AS stockdispo
|
sql`SELECT a.codein::text AS codein, cs.site, COALESCE(cs.qte, 0)::float AS stockdispo
|
||||||
FROM cube_stock cs
|
FROM cube_stock cs
|
||||||
JOIN articles a ON a.no_id = cs.artnoid
|
JOIN articles a ON a.no_id = cs.artnoid
|
||||||
WHERE a.codein = ANY(string_to_array(${codeinsStr}, ','))`
|
WHERE a.codein::text = ANY(string_to_array(${codeinsStr}, ','))`
|
||||||
);
|
);
|
||||||
const rows = result.rows as { codein: string; site: string; stockdispo: number }[];
|
const rows = result.rows as { codein: string; site: string; stockdispo: number }[];
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user