diff --git a/src/index.js b/src/index.js index 990d3a7abb4e6fbd1a2a768ceb9c343c4b7cfd13..af242bf7ae91b33d812453c2106e4c145cc543d7 100644 --- a/src/index.js +++ b/src/index.js @@ -26,13 +26,14 @@ async function start(fields) { const loadProfile = await getData() log('info', 'Saving data to Cozy') storeLoadProfile(loadProfile) + await removeAberrantData() } catch (error) { throw new Error(error.message) } } const startDate = moment() - .subtract(3, 'day') + .subtract(30, 'day') .format('DD/MM/YYYY') const endDate = moment().format('DD/MM/YYYY') @@ -115,3 +116,12 @@ async function resetData() { await cozyClient.data.delete('enedis.loadprofile', load) } } + +async function removeAberrantData() { + const result = await cozyClient.data.findAll('enedis.loadprofile') + for (const load of result) { + if (load.load == -2) { + await cozyClient.data.delete('enedis.loadprofile', load) + } + } +}