diff --git a/src/index.js b/src/index.js index 4af6b62e78273eae2f65c5c02a99847ecac2f5b7..52012923bf6c9e3eb1a3c7566c6fd4a7280b6d6b 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) } /**