diff --git a/manifest.konnector b/manifest.konnector index f9b5284b932f869a6be001de1545d259e1414de5..b9e2ba231ca70d9e21c33b9da6227d5761068a89 100644 --- a/manifest.konnector +++ b/manifest.konnector @@ -11,8 +11,20 @@ "categories": ["energy"], "frequency": "daily", "fields": { + "firstname": { + "type": "string" + }, + "lastname": { + "type": "string" + }, + "address": { + "type": "string" + }, + "postalCode": { + "type": "string" + }, "pointId": { - "type": "text" + "type": "number" } }, "data_types": [ diff --git a/package.json b/package.json index eb3c5f85ada17a90a7928cd8d91bd1490381b56a..87eab8c4ab9a44615f57bef7762ab4a9456bd7d2 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,6 @@ "build", "data" ], - "husky": { - "hooks": { - "pre-commit": "yarn lint" - } - }, "scripts": { "start": "node ./src/index.js", "dev": "cozy-konnector-dev", diff --git a/src/core/contractActivation.js b/src/core/contractActivation.js index d12a855c4cbd2c1f33b514bb18390739fc56bb3f..0e8242f58d5e7d3a7fee90fb2983a9728f642b76 100644 --- a/src/core/contractActivation.js +++ b/src/core/contractActivation.js @@ -10,7 +10,7 @@ const xml2js = require('xml2js') * @param {string} apiAuthKey * @param {string} appLogin * @param {string} name - * @param {string} pointId + * @param {number} pointId * @param {string} startDate * @param {string} endDate * @return {Promise<number>} User contractId @@ -57,7 +57,7 @@ async function activateContract( try { return parseServiceId(parsedReply) } catch (error) { - log('error', 'Error while parsing user PDL: ' + error) + log('error', 'Error whileactivating contract: ' + error) throw errors.LOGIN_FAILED } } diff --git a/src/core/contractTermination.js b/src/core/contractTermination.js index 9334f85679a9483045b2a3d5b6c3500922d9cd5f..aa127c07e7d0527bcc2effbfc299a3968b347f29 100644 --- a/src/core/contractTermination.js +++ b/src/core/contractTermination.js @@ -9,7 +9,7 @@ const xml2js = require('xml2js') * @param {string} url * @param {string} apiAuthKey * @param {string} appLogin - * @param {string} pointId + * @param {number} pointId * @param {number} serviceId * @return {Promise<string>} User contractId */ diff --git a/src/core/contractVerification.js b/src/core/contractVerification.js index fc9558a488d8d1ca5ad59f7f08e3e72d58e4a7c2..1bd598a9e424d2a424cc9ee1bb27c4db7fd6f3dd 100644 --- a/src/core/contractVerification.js +++ b/src/core/contractVerification.js @@ -10,7 +10,7 @@ const { contractState } = require('./types/enum') * @param {string} url * @param {string} apiAuthKey * @param {string} appLogin - * @param {string} pointId + * @param {number} pointId * @return {Promise<number | null>} User contractId */ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) { diff --git a/src/core/types/types.js b/src/core/types/types.js index 99452fd781f16799671b98cba8b5fa473cf45f90..326b4e6dc084163be96d48154fd3965b80b8b676 100644 --- a/src/core/types/types.js +++ b/src/core/types/types.js @@ -22,14 +22,16 @@ * @property {string} apiToken * @property {string} sgeLogin * @property {string} contractId - * @property {unumber} pointId + * @property {number} pointId + * @property {string} lastname */ /** * Consent definition * @typedef {object} Consent * @property {number} pointId - * @property {string} name + * @property {string} lastname + * @property {string} firstname * @property {string} address * @property {string} postalCode * @property {string} inseeCode @@ -40,8 +42,9 @@ /** * User definition * @typedef {object} User - * @property {string} pointId - * @property {string} name + * @property {number} pointId + * @property {string} lastname + * @property {string} firstname * @property {string} postalCode * @property {string} address * @property {string} inseeCode diff --git a/src/core/verifyUserIdentity.js b/src/core/verifyUserIdentity.js index 0e67cc691244be45fbbabf4e24cfb42dc347ae12..89ad807a38b6b7783b75b440ea4480a79775496a 100644 --- a/src/core/verifyUserIdentity.js +++ b/src/core/verifyUserIdentity.js @@ -23,7 +23,7 @@ async function verifyUserIdentity( `${baseUrl}/enedis_SDE_recherche-point/1.0`, apiAuthKey, loginUtilisateur, - fields.name, + fields.lastname, fields.address, fields.postalCode, inseeCode @@ -35,7 +35,8 @@ async function verifyUserIdentity( } return { - name: fields.name, + lastname: fields.lastname, + firstname: fields.firstname, pointId: fields.pointId, inseeCode, postalCode: fields.postalCode, diff --git a/src/index.js b/src/index.js index 887b1da82e9bf6001f7dfeb1034066a097e1e44c..170c5bccd0acd9e68554ab6169b270a259b0df52 100644 --- a/src/index.js +++ b/src/index.js @@ -95,7 +95,7 @@ async function start(fields, cozyParameters) { let consent = await createBoConsent( pointId, - user.name, + user.lastname, user.address, user.postalCode, user.inseeCode @@ -121,7 +121,7 @@ async function start(fields, cozyParameters) { apiAuthKey, sgeLogin, fields.contractId, - user.name, + user.lastname, user.pointId, contractStartDate, contractEndDate @@ -144,7 +144,8 @@ async function start(fields, cozyParameters) { const accountData = await getAccount(ACCOUNT_ID) const userConsent = await getBoConsent(accountData.data.consentId) const user = await verifyUserIdentity(fields, baseUrl, apiAuthKey, sgeLogin) - if (user.name !== userConsent.name || !user) { + console.log(user) + if (user.lastname !== userConsent.lastname || !user) { log('error', `Invalid or not found consent for user`) await deleteBoConsent() if (userConsent.serviceId) { diff --git a/src/requests/bo.js b/src/requests/bo.js index 88fb3fc98cd4fb7ae8e44646677eaabac52c57e0..e3710e2785ee4d9484d1647b65832e1fd81be541 100644 --- a/src/requests/bo.js +++ b/src/requests/bo.js @@ -45,7 +45,8 @@ function getBoConsent(boId) { log('info', `Query getBoConsent`) return { pointId: 1234, - name: 'SUBTIL', + lastname: 'SUBTIL', + firstname: 'hugo', address: 'mad', postalCode: '69007', inseeCode: '69383', diff --git a/src/requests/sge.js b/src/requests/sge.js index 30b2b87634661f5ca83f47f31bd23b8416e98fcf..518c624b5d2136bff45fef03e22d96accbc0e137 100644 --- a/src/requests/sge.js +++ b/src/requests/sge.js @@ -159,7 +159,7 @@ function rechercherPoint(appLogin, name, postalCode, inseeCode, address) { * Search if user as a service * @param {string} appLogin * @param {string} contractId - * @param {string} pointId + * @param {number} pointId * @returns {*} */ function rechercherServicesSouscritsMesures(appLogin, contractId, pointId) { @@ -185,7 +185,7 @@ function rechercherServicesSouscritsMesures(appLogin, contractId, pointId) { * Activate half hour data collect for user * @param {string} appLogin * @param {string} contractId - * @param {string} pointId + * @param {number} pointId * @param {string} name * @param {string} startDate * @param {string} endDate @@ -244,7 +244,7 @@ function commanderCollectePublicationMesures( * Stop the user consent * @param {string} appLogin * @param {string} contractId - * @param {string} pointId + * @param {number} pointId * @param {number} serviceSouscritId * @returns {*} */