From a9d572b800342584d840c3b0d6a27043aee850ca Mon Sep 17 00:00:00 2001 From: Hugo <hnouts.dev@gmail.com> Date: Wed, 24 Feb 2021 17:10:15 +0100 Subject: [PATCH] await on hydrate&filter --- src/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 4af6b62..5201292 100644 --- a/src/index.js +++ b/src/index.js @@ -242,17 +242,19 @@ function reduceMonthFunction(acc, x) { return acc; } -async function storeData(data, doctype, keys) { +/** + * Save data in the right doctype db and prevent duplicated keys + */ +async function storeData(data, doctype, filterKeys) { log("debug", "Store into " + doctype); - log("debug", "Store into keys : " + keys); + log("debug", "Store into keys : " + filterKeys); data.map(v => { log("info", "Saving data " + v.load + " for " + v.day + "/" + v.month + "/" + v.year); }); - return hydrateAndFilter(data, doctype, { - keys: keys - }).then(filteredDocuments => { - addData(filteredDocuments, doctype); - }); + const filteredDocuments = await hydrateAndFilter(data, doctype, { + keys: filterKeys + }) + return await addData(filteredDocuments, doctype) } /** -- GitLab