From 50888281cbe5a812e46762be160282bd7ab5a421 Mon Sep 17 00:00:00 2001
From: i-vall <ivallanzasca@gmail.com>
Date: Fri, 5 Jul 2019 13:46:25 +0200
Subject: [PATCH] publish: fix(removeAberrantData): removal of data executes
 last

generated from commit f5fe857ef7e6c6bcf8ee617a2a0ba2c7648bdc7d
---
 index.js | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/index.js b/index.js
index 48ddb86..6f5963b 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
-- 
GitLab