From d74cdeb7b38456b26d49a03aa3a5b515ef360d0c Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Thu, 9 Apr 2026 08:18:10 +0200 Subject: [PATCH] feat: implement automated procurement synchronization and API endpoints for supply chain management --- sync/db.js | 4 ++++ sync/tables/appro.js | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sync/db.js b/sync/db.js index d8ca9df..eeff1cd 100644 --- a/sync/db.js +++ b/sync/db.js @@ -24,6 +24,10 @@ let pgPool = null; async function getMssql() { if (!mssqlPool) { mssqlPool = await sql.connect(mssqlConfig); + mssqlPool.on('error', (err) => { + console.error('[mssql] Pool error, reconnexion au prochain appel:', err.message); + mssqlPool = null; + }); } return mssqlPool; } diff --git a/sync/tables/appro.js b/sync/tables/appro.js index e800eef..43b2dc0 100644 --- a/sync/tables/appro.js +++ b/sync/tables/appro.js @@ -29,11 +29,11 @@ const PLAN_REAPPRO_COLS = [ ]; async function syncAppro(force) { - const ms = await getMssql(); - const pg = getPg(); + const pg = getPg(); // === COMMANDE_FOU (upsert delta) === try { + const ms = await getMssql(); const lastSync = force ? null : await getLastSync(pg, 'commande_fou'); const where = lastSync ? `WHERE SUIVIDATEMODIF > '${lastSync.toISOString()}'` : ''; @@ -72,6 +72,7 @@ async function syncAppro(force) { // === CDEFOU_LIGNE (upsert delta) === try { + const ms = await getMssql(); const lastSync = force ? null : await getLastSync(pg, 'cdefou_ligne'); const where = lastSync ? `WHERE SUIVIDATEMODIF > '${lastSync.toISOString()}'` : '';