From d99d34892801eb213342f59a77809b78bdf02d1a Mon Sep 17 00:00:00 2001
From: git-directory-deploy <>
Date: Wed, 27 Jan 2021 14:32:26 +0100
Subject: [PATCH] publish:  consent for load curve data and manual execution

generated from commit 1ca126af82b1ff8cf8dab48e199e0315e9dc4e80
---
 index.js | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/index.js b/index.js
index 61d65f9..cc0b86a 100644
--- a/index.js
+++ b/index.js
@@ -317,6 +317,28 @@ async function checkConsentForLoadCurve(
   }
 }
 
+/**
+ * Function checking if the history is loaded
+ */
+async function isHistoryLoaded(doctype) {
+  log('debug', doctype, 'Retrieve data')
+  const result = await cozyClient.data.findAll(doctype)
+  if (result && result.length > 0) {
+    const filtered = result.filter(function(el) {
+      const elDate = moment({ year : el.year, month : el.month, day : el.day})
+      return (
+        elDate.isBefore(startLoadDate)
+      )
+    })
+    if (filtered.length > 0) {
+      return false
+    } else {
+      return true
+    }
+  }
+  return false
+}
+
 /**
  * Launch process to handle load data
  */
@@ -548,29 +570,6 @@ async function buildDataFromKey(doctype, key, value) {
   }
 }
 
-/**
- * Function checking if the history is loaded
- */
-async function isHistoryLoaded(doctype) {
-  log('debug', doctype, 'Retrieve data')
-  const result = await cozyClient.data.findAll(doctype)
-  if (result && result.length > 0) {
-    const filtered = result.filter(function(el) {
-      return (
-        el.year <= startLoadDate.year &&
-        el.month <= startLoadDate.month &&
-        el.day <= startLoadDate.day-1
-      )
-    })
-    if (filtered.length > 0) {
-      return false
-    } else {
-      return true
-    }
-  }
-  return false
-}
-
 /**
  * Function handling special case.
  * The temporary aggregated data need to be remove in order for the most recent one te be saved.
-- 
GitLab