From a4243c4134fd35332a6d19cfe1ab611cb0ee866f Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Wed, 21 Sep 2022 13:13:11 +0000 Subject: [PATCH] feat: reduce fetching data to 1y on manual exec --- konnector-dev-config.example.json | 17 +++++++++++++++++ src/index.js | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 konnector-dev-config.example.json diff --git a/konnector-dev-config.example.json b/konnector-dev-config.example.json new file mode 100644 index 0000000..cf79cb7 --- /dev/null +++ b/konnector-dev-config.example.json @@ -0,0 +1,17 @@ +{ + "COZY_URL": "http://cozy.tools:8080", + "fields": { + "pointId": 0, + "lastname": "", + "firstname": "", + "postalCode": "69003", + "address": "", + "city": "Lyon", + "sgeLogin": "", + "boBaseUrl": "", + "boToken": "", + "contractId": "", + "wso2BaseUrl": "", + "apiToken": "" + } +} diff --git a/src/index.js b/src/index.js index 899af77..e57d273 100644 --- a/src/index.js +++ b/src/index.js @@ -65,6 +65,7 @@ module.exports = new BaseKonnector(start) */ async function start(fields, cozyParameters) { log('info', 'Konnector configuration ...') + log('info', `isManual exectuion: ${manualExecution}`) const pointId = parseInt(fields.pointId) let baseUrl = fields.wso2BaseUrl @@ -107,6 +108,7 @@ async function start(fields, cozyParameters) { log('info', 'User Logging...') if (isFirstStart(await getAccount(ACCOUNT_ID))) { + log('info', 'First start...') const user = await verifyUserIdentity(fields, baseUrl, apiAuthKey, sgeLogin) let consent = await createBoConsent( @@ -371,7 +373,8 @@ 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. + * On manual execution, set the start date to one year ago. */ function setStartDate() { if (moment(endDate).diff(startDailyDate, 'months', true) > 36) { @@ -382,6 +385,10 @@ function setStartDate() { startDailyDate = moment(endDate).subtract(36, 'month') startDailyDateString = startDailyDate.format('YYYY-MM-DD') } + if (manualExecution) { + startDailyDate = moment(endDate).subtract(12, 'month') + startDailyDateString = startDailyDate.format('YYYY-MM-DD') + } } /** -- GitLab