From f5fe857ef7e6c6bcf8ee617a2a0ba2c7648bdc7d Mon Sep 17 00:00:00 2001 From: i-vall <ivallanzasca@gmail.com> Date: Fri, 5 Jul 2019 13:44:21 +0200 Subject: [PATCH] fix(removeAberrantData): removal of data executes last --- src/index.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 7798b0d..95784a0 100644 --- a/src/index.js +++ b/src/index.js @@ -28,8 +28,9 @@ async function start(fields) { log('info', 'Getting data') const loadProfile = await getData() log('info', 'Saving data to Cozy') - storeLoadProfile(loadProfile) - await removeAberrantData() + await storeLoadProfile(loadProfile) + log('info', 'Removing aberrant data') + removeAberrantData() } catch (error) { throw new Error(error.message) } @@ -100,12 +101,16 @@ async function getData() { } } -function storeLoadProfile(loadProfile) { - return hydrateAndFilter(loadProfile, 'enedis.loadprofile', { - keys: ['time'] - }).then(filteredDocuments => { - addData(filteredDocuments, 'enedis.loadprofile') - }) +async function storeLoadProfile(loadProfile) { + const filteredDocuments = await hydrateAndFilter( + loadProfile, + 'enedis.loadprofile', + { + keys: ['time'] + } + ) + const data = await addData(filteredDocuments, 'enedis.loadprofile') + return data } // eslint-disable-next-line no-unused-vars -- GitLab