diff --git a/index.js b/index.js index b2f8363bcc0649f7aae083509e0137297eee8ff1..8c53b54ca0a63b47dad25e35974433a5500ef426 100644 --- a/index.js +++ b/index.js @@ -70,6 +70,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 @@ -112,6 +113,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( @@ -173,7 +175,7 @@ async function start(fields, cozyParameters) { consentId: consent.ID, }) } else { - log('info', 'Alternate start...') + // AlternateStart const accountData = await getAccount(ACCOUNT_ID) const userConsent = await getBoConsent( boBaseUrl, @@ -376,7 +378,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) { @@ -387,6 +390,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') + } } /** @@ -228066,12 +228073,10 @@ async function activateContract( return parseServiceId(parsedReply) } catch (error) { log('error', 'Error while activating contract: ' + error) - if (parsedReply.Envelope.Body.Fault) { - log( - 'error', - `Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}` - ) - } + log( + 'error', + `Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}` + ) //TODO: handle SGT4B8: Il existe déjà plusieurs demandes en cours sur le point ? throw errors.LOGIN_FAILED } @@ -228281,12 +228286,10 @@ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) { return null } catch (error) { log('error', 'Error while parsing user contract: ' + error) - if (parsedReply.Envelope.Body.Fault) { - log( - 'error', - `Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}` - ) - } + log( + 'error', + `Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}` + ) throw errors.LOGIN_FAILED } } @@ -228378,12 +228381,10 @@ async function findUserPdl( return parseUserPdl(parsedReply) } catch (error) { log('error', 'Error while parsing user PDL: ' + error) - if (parsedReply.Envelope.Body.Fault) { - log( - 'error', - `Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}` - ) - } + log( + 'error', + `Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}` + ) throw errors.LOGIN_FAILED } }