diff --git a/index.js b/index.js index 6cf873ef1f09e17c3917a59d16621d3f7ebfb884..a08278de68087172ebb3297616aae8fe159be109 100644 --- a/index.js +++ b/index.js @@ -153,6 +153,7 @@ async function start(fields, cozyParameters) { */ log('info', 'User Logging...') + const boUrlSGE = new URL('/api/sge', boBaseUrl).href if (isFirstStart(await getAccount(ACCOUNT_ID))) { log('info', 'First start...') transaction.startChild({ op: 'First start' }) @@ -166,7 +167,7 @@ async function start(fields, cozyParameters) { exitIfDebug(user) let consent = await createBoConsent( - boBaseUrl, + boUrlSGE, boToken, pointId, user.lastname, @@ -201,12 +202,12 @@ async function start(fields, cozyParameters) { contractStartDate, contractEndDate ).catch(async err => { - await deleteBoConsent(boBaseUrl, boToken, consent.ID) + await deleteBoConsent(boUrlSGE, boToken, consent.ID) throw err }) } consent = await updateBoConsent( - boBaseUrl, + boUrlSGE, boToken, consent, serviceId.toString() @@ -225,7 +226,7 @@ async function start(fields, cozyParameters) { transaction.startChild({ op: 'Alternate start' }) const accountData = await getAccount(ACCOUNT_ID) const userConsent = await getBoConsent( - boBaseUrl, + boUrlSGE, boToken, accountData.data.consentId ) @@ -264,7 +265,7 @@ async function start(fields, cozyParameters) { sgeLogin, contractId, pointId, - boBaseUrl, + boUrlSGE, boToken, consentEndDate < today ) @@ -352,24 +353,13 @@ async function deleteConsent( */ async function gatherData(baseUrl, apiAuthKey, sgeLogin, pointId) { log('info', 'Querying data...') - await getData( - `${baseUrl}/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0`, - apiAuthKey, - sgeLogin, - pointId - ) - await getMaxPowerData( - `${baseUrl}/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0`, - apiAuthKey, - sgeLogin, - pointId - ) - await getDataHalfHour( - `${baseUrl}/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0`, - apiAuthKey, - sgeLogin, - pointId - ) + const measuresUrl = new URL( + '/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0', + baseUrl + ).href + await getData(measuresUrl, apiAuthKey, sgeLogin, pointId) + await getMaxPowerData(measuresUrl, apiAuthKey, sgeLogin, pointId) + await getDataHalfHour(measuresUrl, apiAuthKey, sgeLogin, pointId) log('info', 'Querying data: done') }