From 8d9eb39f60bd4429d14e8e0bf21ecab839206030 Mon Sep 17 00:00:00 2001 From: folland87 Date: Fri, 6 Dec 2024 15:19:14 +0100 Subject: [PATCH] fix imports --- src/jobs/sirene/fetcher.js | 2 +- src/jobs/sirene/index.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/jobs/sirene/fetcher.js b/src/jobs/sirene/fetcher.js index ce34a4da..494d163d 100644 --- a/src/jobs/sirene/fetcher.js +++ b/src/jobs/sirene/fetcher.js @@ -133,7 +133,7 @@ export const fetchSirenDataById = async (sirenId) => { } }; -const fetchSiretDataById = async (siretId) => { +export const fetchSiretDataById = async (siretId) => { const structure = { siren: siretId.slice(0, 9), siret: siretId, diff --git a/src/jobs/sirene/index.js b/src/jobs/sirene/index.js index 4114f505..8730e28b 100644 --- a/src/jobs/sirene/index.js +++ b/src/jobs/sirene/index.js @@ -32,15 +32,16 @@ export default async function monitorSiren(job) { updatesInSirene.some((update) => update.siret === siret), ); console.log(stockToBeUpdated?.length, stockToBeUpdated); - const stockUpdates = stockToBeUpdated.map((stockElement) => { - const siretData = fetchSiretDataById(stockElement.siret); - const sireneData = fetchSirenDataById(stockElement.siren); - return { + const stockUpdates = []; + for (const stockElement of stockToBeUpdated) { + const siretData = await fetchSiretDataById(stockElement.siret); + const sireneData = await fetchSirenDataById(stockElement.siren); + stockUpdates.push({ ...stockElement, siretData, sireneData, - }; - }); + }); + } const ok = await db.collection("_siren").insertMany(stockUpdates); return { status: ok ? "success" : "failed", lastExecution: now };