diff --git a/index.js b/index.js index f1c0b095e6c30db3fe2b9255b9f16e435de1b987..0ee341c5510ba7ff131c1a5b2aee23844bbdeb26 100644 --- a/index.js +++ b/index.js @@ -365,17 +365,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) } /**