diff --git a/src/index.js b/src/index.js index 7798b0d0c775953c3927e50e0a119b4d7820d343..95784a01016770428a95dfdd66ea7549e7ef8d76 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