mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-19 13:08:11 +02:00
feat: implement direct PostgreSQL bulk querying for FF Nancy data to replace per-article HTTP requests
This commit is contained in:
1 parent
13414c970c
commit
7bf42dfc01
5 files changed
+268
-2
No files matched your search
@@ -828,3 +828,41 @@ export async function pgGetStockForCodeins(codeins: string[]): Promise<Map<strin
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Stock négatif — tous magasins ou par site
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export interface PgStockNegatifRow {
|
||||
codein: string;
|
||||
libelle1: string;
|
||||
fournisseur: string;
|
||||
site: string;
|
||||
stockdispo: number;
|
||||
dernierevente: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne tous les articles avec un stock disponible négatif.
|
||||
* Si `site` est fourni, filtre sur ce magasin uniquement.
|
||||
*/
|
||||
export async function pgGetStockNegatif(site?: string): Promise<PgStockNegatifRow[]> {
|
||||
const siteFilter = site ? sql`AND cs.site = ${site}` : sql``;
|
||||
const result = await pgNoParallel(sql`
|
||||
SELECT
|
||||
a.codein,
|
||||
COALESCE(a.libelle1, '') AS libelle1,
|
||||
COALESCE(f.nom, af.code) AS fournisseur,
|
||||
cs.site,
|
||||
cs.stockdispo::float,
|
||||
cs.dernierevente::text
|
||||
FROM cube_stock cs
|
||||
JOIN articles a ON a.no_id = cs.artnoid
|
||||
JOIN artfou1 af ON af.art_no_id = a.no_id AND af.preference = 1
|
||||
JOIN fouident f ON f.code = af.code
|
||||
WHERE cs.stockdispo < 0
|
||||
${siteFilter}
|
||||
ORDER BY cs.stockdispo ASC
|
||||
`);
|
||||
return result.rows as PgStockNegatifRow[];
|
||||
}
|
||||
Reference in new issue
Block a user