From 2e829b038cf254b913ab96d0552ee9aa8bb762c3 Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Fri, 7 Oct 2022 14:20:36 +0200
Subject: [PATCH] publish: fix: error to warn log

generated from commit 0741d040cf873b2c8785ae4192ee472295b00b98
---
 index.js | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/index.js b/index.js
index e564889..f3ed52e 100644
--- a/index.js
+++ b/index.js
@@ -393,12 +393,16 @@ async function getMaxPowerData(url, apiAuthKey, userLogin, pointId) {
 
 /**
  * If start date exceed the maximum amount of data we can get with one query
- * get only 36 month.
+ * get only 36 month. Or 12 month if manual execution
  * On manual execution, set the start date to one year ago.
  */
 function limitStartDate() {
   const livingDuration = moment(endDate).diff(startDailyDate, 'months', true)
-  if (livingDuration > 36) {
+  // We need to prevent case that there is less than 12 month data
+  if (manualExecution && livingDuration > 12) {
+    startDailyDate = moment(endDate).subtract(12, 'month')
+    startDailyDateString = startDailyDate.format('YYYY-MM-DD')
+  } else if (livingDuration > 36) {
     log(
       'info',
       'Start date exceed 36 month, setting start date to current date minus 36 month'
@@ -406,10 +410,6 @@ function limitStartDate() {
     startDailyDate = moment(endDate).subtract(36, 'month')
     startDailyDateString = startDailyDate.format('YYYY-MM-DD')
   }
-  if (manualExecution && livingDuration > 12) {
-    startDailyDate = moment(endDate).subtract(12, 'month')
-    startDailyDateString = startDailyDate.format('YYYY-MM-DD')
-  }
 }
 
 /**
-- 
GitLab