From 2629057cc0e2e280760b99653dca008ce5ab58fe Mon Sep 17 00:00:00 2001
From: "ext.sopra.yvallet@grandlyon.com" <ext.sopra.yvallet@grandlyon.com>
Date: Fri, 19 Feb 2021 11:14:41 +0100
Subject: [PATCH] publish: fix typo

generated from commit 0cab72aeeb2524fd9394b6920e8209d8f71ab8cc
---
 index.js | 57 ++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 39 insertions(+), 18 deletions(-)

diff --git a/index.js b/index.js
index d9b5c6f..4df584d 100644
--- a/index.js
+++ b/index.js
@@ -170,8 +170,6 @@ async function start(fields, cozyParameters) {
     // await resetData()
     const baseUrl = cozyParameters.secret.eglBaseURL
     const apiAuthKey = cozyParameters.secret.eglAPIAuthKey
-    log('info', 'Start fields are : ' + fields)
-
     log('info', 'Authenticating ...')
     const response = await authenticate(
       fields.login,
@@ -273,23 +271,46 @@ async function getData(response, baseUrl, apiAuthKey) {
 }
 
 function format(response) {
-  const data = response.resultatRetour.slice(1).map((value, index) => {
-    const time = moment(value.DateReleve, moment.ISO_8601)
-    log('info', 'SUBSTRACTING : ' + value.ValeurIndex + ' - ' + response.resultatRetour[index].ValeurIndex + '\n')
-    return {
-      // Add if/else to not substract null value (typeagregat T)
-      load: value.TypeAgregat === 'T' ? null : value.ValeurIndex - response.resultatRetour[index].ValeurIndex,
-      year: parseInt(time.format('YYYY')),
-      month: parseInt(time.format('M')),
-      day: parseInt(time.format('D')),
-      hour: 0,
-      minute: 0,
-      type: value.TypeAgregat
-    }
-  })
+  const data = response.resultatRetour
+    .slice(1)
+    .filter(value => {
+      value.TypeAgregat === 'R'
+    })
+    .map((value, index) => {
+      const time = moment(value.DateReleve, moment.ISO_8601)
+      log(
+        'info',
+        'date -> ' +
+          value.DateReleve +
+          ' SUBSTRACTING : ' +
+          value.ValeurIndex +
+          ' - ' +
+          response.resultatRetour[index].ValeurIndex +
+          '\n'
+      )
+      return {
+        load: value.ValeurIndex - response.resultatRetour[index].ValeurIndex,
+        year: parseInt(time.format('YYYY')),
+        month: parseInt(time.format('M')),
+        day: parseInt(time.format('D')),
+        hour: 0,
+        minute: 0,
+        type: value.TypeAgregat
+      }
+    })
   log('info', 'DATALOAD LIST\n')
-  data.map((value) => {
-    log('info', value.month + '-' + value.day + '-' + value.year + ' : ' + value.load + '\n')
+  data.map(value => {
+    log(
+      'info',
+      value.month +
+        '-' +
+        value.day +
+        '-' +
+        value.year +
+        ' : ' +
+        value.load +
+        '\n'
+    )
   })
   return data
 }
-- 
GitLab