From b4f1b5ede4bd8fa505ad362a3db2f5256695a3f7 Mon Sep 17 00:00:00 2001 From: i-vall <ivallanzasca@gmail.com> Date: Mon, 1 Jul 2019 15:31:35 +0200 Subject: [PATCH] feat: remove aberrant data --- src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 990d3a7..af242bf 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) + } + } +} -- GitLab