diff --git a/index.js b/index.js index 48ddb86324d1a7084a44789721c7161de7970533..6f5963b638cd3c5923cc68d86cd7dd5124972d46 100644 --- a/index.js +++ b/index.js @@ -151,8 +151,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) } @@ -223,12 +224,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