From 13c1f2105a8ad0ce50f3f8f04b9c9933e3d86e3d Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Thu, 1 Dec 2022 12:36:19 +0000 Subject: [PATCH] fix: issue-contract-less-than-6-month --- src/core/contractVerification.js | 9 ++++----- src/core/types/enum.js | 12 +----------- src/index.js | 15 ++++++++++++--- src/requests/cozy.js | 1 - 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/core/contractVerification.js b/src/core/contractVerification.js index 7b559ce..d1a2606 100644 --- a/src/core/contractVerification.js +++ b/src/core/contractVerification.js @@ -9,7 +9,7 @@ const { } = require('../helpers/parsing') const { rechercherServicesSouscritsMesures } = require('../requests/sge') const xml2js = require('xml2js') -const { contractState, contractLibelle } = require('./types/enum') +const { contractState } = require('./types/enum') /** * @param {string} url @@ -55,9 +55,8 @@ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) { currentContract = currentContracts } if ( - (currentContract.etatCode === contractState.ACTIF || - currentContract.etatCode === contractState.DEMANDE) && - currentContract.serviceSouscritLibelle === contractLibelle.ACTIF + currentContract.etatCode === contractState.ACTIF || + currentContract.etatCode === contractState.DEMANDE ) return currentContract.serviceSouscritId return null @@ -71,7 +70,7 @@ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) { } log( 'error', - 'if an erorr is thrown here, it probably means that the contract has already been open today and that enedis cannot open a second one. Wait until tomorow to try again' + 'if an error is thrown here, it probably means that the contract has already been open today and that enedis cannot open a second one. Wait until tomorow to try again' ) throw errors.LOGIN_FAILED } diff --git a/src/core/types/enum.js b/src/core/types/enum.js index 485c3f7..8bcc6f3 100644 --- a/src/core/types/enum.js +++ b/src/core/types/enum.js @@ -9,14 +9,4 @@ const contractState = { DEMANDE: 'DEMANDE', } -/** - * Enum for contractLibelle values. - * @readonly - * @enum {number} - */ -const contractLibelle = { - ACTIF: - 'Collecte de la courbe de charge au pas 30 min avec transmission quotidienne des données brutes en soutirage', -} - -module.exports = { contractState, contractLibelle } +module.exports = { contractState } diff --git a/src/index.js b/src/index.js index a3a93d5..7d1c7c2 100644 --- a/src/index.js +++ b/src/index.js @@ -277,7 +277,16 @@ async function deleteConsent( */ async function gatherData(baseUrl, apiAuthKey, sgeLogin, pointId) { log('info', 'Querying data...') - await getContractStartDate(baseUrl, apiAuthKey, sgeLogin, pointId) + const userContractstartDate = await getContractStartDate( + baseUrl, + apiAuthKey, + sgeLogin, + pointId + ) + + startDailyDate = moment(userContractstartDate, 'YYYY-MM-DD') + startDailyDateString = startDailyDate.format('YYYY-MM-DD') + await getData( `${baseUrl}/enedis_SGE_ConsultationMesuresDetaillees/1.0`, apiAuthKey, @@ -482,9 +491,9 @@ function processData(doctype = 'com.grandlyon.enedis.day') { ['year', 'month', 'day', 'hour', 'minute'] ) - log('info', 'Agregate enedis daily data for month and year') + log('info', 'Aggregate enedis daily data for month and year') if (doctype === 'com.grandlyon.enedis.day') { - log('info', 'Agregating...') + log('info', 'Aggregating...') await agregateMonthAndYearData(processedDailyData) } } catch (e) { diff --git a/src/requests/cozy.js b/src/requests/cozy.js index 2e22ceb..71bc1f7 100644 --- a/src/requests/cozy.js +++ b/src/requests/cozy.js @@ -39,7 +39,6 @@ async function saveAccountData(accountId, accountData) { async function getAccount(accountId) { log('info', `getAccount: ${accountId}`) const accounts = await cozyClient.data.findAll('io.cozy.accounts') - log('info', `getAccount data: ${JSON.stringify(accounts)}`) return accounts.filter(account => isLocal() ? account._id === accountId : account.account_type === accountId )[0] -- GitLab