From 9866fe358b1aca706e1dcc69a3fe38ae9406503a Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Wed, 7 Feb 2024 12:14:42 +0000 Subject: [PATCH] chore: update backoffice endpoint parsing --- README.md | 2 +- src/core/verifyUserIdentity.js | 2 +- src/index.js | 36 ++++++++++++---------------------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index f70e988..b01b30f 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ Retrieving consumption data from Enedis SGE SOAP api ## Documentation -[Enedis SGE Konnector - Self-Data](https://doc.self-data.alpha.grandlyon.com/konnectors/enedis-sge/) +[Enedis SGE Konnector - Self-Data](https://doc-self-data.apps.grandlyon.com/konnectors/enedis-sge/) diff --git a/src/core/verifyUserIdentity.js b/src/core/verifyUserIdentity.js index a7376fd..08a7d20 100644 --- a/src/core/verifyUserIdentity.js +++ b/src/core/verifyUserIdentity.js @@ -38,7 +38,7 @@ async function verifyUserIdentity( // Store if user is going through safety sge onboarding let userSafetyOnBoarding = false - // First try with user adresse + // First try with user address let pdl = await findUserPdl( `${baseUrl}/enedis_SDE_recherche-point/1.0`, apiAuthKey, diff --git a/src/index.js b/src/index.js index 4df3db2..b64aab5 100644 --- a/src/index.js +++ b/src/index.js @@ -148,6 +148,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' }) @@ -161,7 +162,7 @@ async function start(fields, cozyParameters) { exitIfDebug(user) let consent = await createBoConsent( - boBaseUrl, + boUrlSGE, boToken, pointId, user.lastname, @@ -196,12 +197,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() @@ -220,7 +221,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 ) @@ -259,7 +260,7 @@ async function start(fields, cozyParameters) { sgeLogin, contractId, pointId, - boBaseUrl, + boUrlSGE, boToken, consentEndDate < today ) @@ -347,24 +348,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') } -- GitLab