diff --git a/.vscode/settings.json b/.vscode/settings.json index 11f23f13742cfb0099c5f9b420c12bd6c34fa8da..5024404b933b68aed303d8ee8a97c697c3089bcd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,16 +18,39 @@ "titleBar.inactiveBackground": "#42b88399", "titleBar.inactiveForeground": "#15202b99" }, + "editor.codeActionsOnSave": { + "source.fixAll": true, + "source.organizeImports": true + }, "cSpell.words": [ + "acces", "apikey", + "arret", + "Arret", "backoffice", + "Corrigees", + "cozyclient", + "criteres", "Derniere", "Detaillees", "enedissgegrandlyon", + "Etage", + "etat", + "faultstring", + "firstname", + "Generales", "grandlyon", "HISTO", "insee", "konnectors", - "maxpower" + "lastname", + "maxpower", + "numero", + "Perimetre", + "periodicite", + "PMAX", + "Recurrente", + "resultat", + "soapenv" ] } diff --git a/__tests__/helpers/aggregate.spec.js b/__tests__/helpers/aggregate.spec.js index f5b64cb00bdcd829a884269fb73ab50d2d28e008..abd30699dc7a3d1f389e43c8afc3b39e60e42c22 100644 --- a/__tests__/helpers/aggregate.spec.js +++ b/__tests__/helpers/aggregate.spec.js @@ -1,13 +1,13 @@ -const { buildAgregatedData } = require('../../src/helpers/aggregate') +const { buildAggregatedData } = require('../../src/helpers/aggregate') const { cozyClient } = require('cozy-konnector-libs') -describe('buildAgregatedData', () => { +describe('buildAggregatedData', () => { it('should return empty', async () => { - const reply = await buildAgregatedData([], 'com.enedis.day') + const reply = await buildAggregatedData([], 'com.enedis.day') expect(reply).toEqual([]) }) it('should return year value', async () => { - const reply = await buildAgregatedData( + const reply = await buildAggregatedData( { '2022': 36, }, @@ -27,7 +27,7 @@ describe('buildAgregatedData', () => { it('should return year value with doc existing', async () => { const spy = jest.spyOn(cozyClient.data, 'findAll') spy.mockResolvedValueOnce([{ year: 2022, month: 8, day: 1, load: 1 }]) - const reply = await buildAgregatedData( + const reply = await buildAggregatedData( { '2022': 36, }, @@ -47,7 +47,7 @@ describe('buildAgregatedData', () => { it('should return month value', async () => { const spy = jest.spyOn(cozyClient.data, 'findAll') spy.mockResolvedValueOnce([{ year: 2022, month: 8, day: 1, load: 1 }]) - const reply = await buildAgregatedData( + const reply = await buildAggregatedData( { '2022-08': 36, }, @@ -69,7 +69,7 @@ describe('buildAgregatedData', () => { spy.mockResolvedValueOnce([ { year: 2022, month: 8, day: 1, load: 1, hour: 13 }, ]) - const reply = await buildAgregatedData( + const reply = await buildAggregatedData( { '2022-08-01-13:39:25+00:00': 36, }, diff --git a/__tests__/helpers/parsing.spec.js b/__tests__/helpers/parsing.spec.js index 37577a3626fcb3db3fd7152d1107147bb4c9aef5..73b2cd9435abbb5898f4693b3a99774cddefb541 100644 --- a/__tests__/helpers/parsing.spec.js +++ b/__tests__/helpers/parsing.spec.js @@ -10,7 +10,7 @@ const { parseTags, parseValue, removeMultipleSpaces, - removeAddressnumber, + removeAddressNumber, } = require('../../src/helpers/parsing') describe('parsing', () => { it('should parse userPdl', () => { @@ -196,29 +196,29 @@ describe('parsing', () => { expect(reply).toBe('20 rue du lac') }) - describe('removeAddressnumber', () => { + describe('removeAddressNumber', () => { it('should remove address number ✅', () => { - const reply = removeAddressnumber('20 rue du lac') + const reply = removeAddressNumber('20 rue du lac') expect(reply).toBe('rue du lac') }) it('should remove B and number ✅', () => { - const reply = removeAddressnumber('20 B rue du lac') + const reply = removeAddressNumber('20 B rue du lac') expect(reply).toBe('rue du lac') }) it('should remove b and number ✅', () => { - const reply = removeAddressnumber('20 B rue du lac') + const reply = removeAddressNumber('20 B rue du lac') expect(reply).toBe('rue du lac') }) it('should remove T and number ✅', () => { - const reply = removeAddressnumber('20 T rue du lac') + const reply = removeAddressNumber('20 T rue du lac') expect(reply).toBe('rue du lac') }) it('should remove t and number ✅', () => { - const reply = removeAddressnumber('20 t rue du lac') + const reply = removeAddressNumber('20 t rue du lac') expect(reply).toBe('rue du lac') }) it('should remove t and number ✅', () => { - const reply = removeAddressnumber('20t rue du lac') + const reply = removeAddressNumber('20t rue du lac') expect(reply).toBe('rue du lac') }) }) diff --git a/importedData.json b/importedData.json index a60a84081c8b9982500f212da31ec8da3e7916cf..4913586c687ca7fbf6bb731c3dba7a85e3665e49 100644 --- a/importedData.json +++ b/importedData.json @@ -2,5 +2,29 @@ "io.cozy.files": [], "com.grandlyon.enedis.year": [], "com.grandlyon.enedis.month": [], - "com.grandlyon.enedis.minute": [] -} + "com.grandlyon.enedis.minute": [], + "io.cozy.accounts": [ + { + "cozyMetadata": { + "doctypeVersion": 1, + "metadataVersion": 1, + "createdAt": "2022-12-02T14:54:25.949Z", + "createdByApp": "enedissgegrandlyon", + "createdByAppVersion": "1.2.0", + "updatedAt": "2022-12-02T14:55:04.810Z", + "updatedByApps": [ + { + "slug": "enedissgegrandlyon", + "date": "2022-12-02T14:55:04.810Z", + "version": "1.2.0" + } + ] + }, + "_id": "1111111", + "account_type": "1111111", + "data": { + "name": "pouet" + } + } + ] +} \ No newline at end of file diff --git a/src/core/verifyUserIdentity.js b/src/core/verifyUserIdentity.js index 3baf0c570c4ca2df1e2aa7c8347ae569ffde6f3c..352447fb768f1580c28fdd0a908cf9c612804ad6 100644 --- a/src/core/verifyUserIdentity.js +++ b/src/core/verifyUserIdentity.js @@ -5,7 +5,7 @@ const { getInseeCode } = require('../requests/insee') const { findUserAddress } = require('./findUserAddress') const { removeMultipleSpaces, - removeAddressnumber, + removeAddressNumber, } = require('../helpers/parsing') const Sentry = require('@sentry/node') @@ -81,7 +81,7 @@ async function verifyUserIdentity( apiAuthKey, loginUtilisateur, fields.lastname, - removeMultipleSpaces(removeAddressnumber(userAddress.numeroEtNomVoie)), + removeMultipleSpaces(removeAddressNumber(userAddress.numeroEtNomVoie)), userAddress.codePostal, userAddress.commune.$.code ) @@ -94,7 +94,7 @@ async function verifyUserIdentity( apiAuthKey, loginUtilisateur, fields.lastname, - removeMultipleSpaces(removeAddressnumber(userAddress.numeroEtNomVoie)), + removeMultipleSpaces(removeAddressNumber(userAddress.numeroEtNomVoie)), userAddress.codePostal, userAddress.commune.$.code, escalierEtEtageEtAppartement diff --git a/src/helpers/aggregate.js b/src/helpers/aggregate.js index 00a66199a0ab12948a565b035171fa7ac60c1b29..640e71ed05864addf1bbbbcc1814632ab5cae2ca 100644 --- a/src/helpers/aggregate.js +++ b/src/helpers/aggregate.js @@ -3,18 +3,18 @@ const { log, cozyClient } = require('cozy-konnector-libs') /** * Retrieve and remove old data for a specific doctype - * Return an Array of agregated data + * Return an Array of aggregated data */ -async function buildAgregatedData(data, doctype) { - let agregatedData = [] +async function buildAggregatedData(data, doctype) { + let aggregatedData = [] // eslint-disable-next-line no-unused-vars for (let [key, value] of Object.entries(data)) { const data = buildDataFromKey(doctype, key, value) const oldValue = await resetInProgressAggregatedData(data, doctype) data.load += oldValue - agregatedData.push(data) + aggregatedData.push(data) } - return agregatedData + return aggregatedData } /** @@ -102,5 +102,5 @@ async function resetInProgressAggregatedData(data, doctype) { } module.exports = { - buildAgregatedData, + buildAggregatedData, } diff --git a/src/helpers/parsing.js b/src/helpers/parsing.js index 26d13c8d754a2f7d59cb4b3b77760b3f2d2620fd..dcb95325c49ef8a575bae3690b0758adc68fb38a 100644 --- a/src/helpers/parsing.js +++ b/src/helpers/parsing.js @@ -167,7 +167,7 @@ function removeMultipleSpaces(str) { * @param {string} str * @returns {string} */ -function removeAddressnumber(str) { +function removeAddressNumber(str) { return str.replace(/\d+ |b |B |T |t |\d+/g, '') } @@ -183,6 +183,6 @@ module.exports = { parseUserPdl, parseValue, parseValueHalfHour, - removeAddressnumber, + removeAddressNumber, removeMultipleSpaces, } diff --git a/src/index.js b/src/index.js index 2c4f8586ea1d418851cd356819434a72f8bfca4d..fe6fe274cf82374d7ac3659a2d2b7b7081630516 100644 --- a/src/index.js +++ b/src/index.js @@ -10,7 +10,7 @@ const soapRequest = require('easy-soap-request') const moment = require('moment') require('moment-timezone') const xml2js = require('xml2js') -const { buildAgregatedData } = require('./helpers/aggregate') +const { buildAggregatedData } = require('./helpers/aggregate') const { parseSgeXmlData, formateDataForDoctype, @@ -147,14 +147,14 @@ async function start(fields, cozyParameters) { ) // handle user contract start date in order to properly request data - const userContractstartDate = await getContractStartDate( + const userContractStartDate = await getContractStartDate( baseUrl, apiAuthKey, sgeLogin, pointId ) - startDailyDate = moment(userContractstartDate, 'YYYY-MM-DD') + startDailyDate = moment(userContractStartDate, 'YYYY-MM-DD') startDailyDateString = startDailyDate.format('YYYY-MM-DD') const contractStartDate = moment().format('YYYY-MM-DD') @@ -304,14 +304,14 @@ async function deleteConsent( */ async function gatherData(baseUrl, apiAuthKey, sgeLogin, pointId) { log('info', 'Querying data...') - const userContractstartDate = await getContractStartDate( + const userContractStartDate = await getContractStartDate( baseUrl, apiAuthKey, sgeLogin, pointId ) - startDailyDate = moment(userContractstartDate, 'YYYY-MM-DD') + startDailyDate = moment(userContractStartDate, 'YYYY-MM-DD') startDailyDateString = startDailyDate.format('YYYY-MM-DD') await getData( @@ -462,7 +462,7 @@ async function getDataHalfHour(url, apiAuthKey, userLogin, pointId) { for (var i = 0; i < MAX_HISTO; i++) { log('info', 'launch process with history') - const increamentedStartDateString = moment(startLoadDate) + const incrementedStartDateString = moment(startLoadDate) .subtract(7 * i, 'day') .format('YYYY-MM-DD') const incrementedEndDateString = moment(endDate) @@ -475,7 +475,7 @@ async function getDataHalfHour(url, apiAuthKey, userLogin, pointId) { xml: consultationMesuresDetaillees( pointId, userLogin, - increamentedStartDateString, + incrementedStartDateString, incrementedEndDateString, 'COURBE', 'PA' @@ -524,7 +524,7 @@ function processData(doctype = 'com.grandlyon.enedis.day') { log('info', 'Aggregate enedis daily data for month and year') if (doctype === 'com.grandlyon.enedis.day') { log('info', 'Aggregating...') - await agregateMonthAndYearData(processedDailyData) + await aggregateMonthAndYearData(processedDailyData) } } catch (e) { if (doctype === 'com.grandlyon.enedis.minute') { @@ -558,7 +558,7 @@ async function storeData(data, doctype, filterKeys) { /** * Aggregate data from daily data to monthly and yearly data */ -async function agregateMonthAndYearData(data) { +async function aggregateMonthAndYearData(data) { // Sum year and month values into object with year or year-month as keys if (data && data.length > 0) { let monthData = {} @@ -571,21 +571,21 @@ async function agregateMonthAndYearData(data) { ? (yearData[element.year] += element.load) : (yearData[element.year] = element.load) }) - // Agregation for Month data - const agregatedMonthData = await buildAgregatedData( + // Aggregation for Month data + const aggregatedMonthData = await buildAggregatedData( monthData, 'com.grandlyon.enedis.month' ) - await storeData(agregatedMonthData, 'com.grandlyon.enedis.month', [ + await storeData(aggregatedMonthData, 'com.grandlyon.enedis.month', [ 'year', 'month', ]) - // Agregation for Year data - const agregatedYearData = await buildAgregatedData( + // Aggregation for Year data + const aggregatedYearData = await buildAggregatedData( yearData, 'com.grandlyon.enedis.year' ) - await storeData(agregatedYearData, 'com.grandlyon.enedis.year', ['year']) + await storeData(aggregatedYearData, 'com.grandlyon.enedis.year', ['year']) } } diff --git a/src/onDeleteAccount.js b/src/onDeleteAccount.js index 658a7cd7310ff650f6722625a0811eb279f19804..e68fd7a920a5047bb3d9393964243cab3d08f63e 100644 --- a/src/onDeleteAccount.js +++ b/src/onDeleteAccount.js @@ -10,11 +10,12 @@ const { terminateContract } = require('./core/contractTermination') const { getAccountForDelete } = require('./requests/cozy') const moment = require('moment') require('moment-timezone') -moment.locale('fr') // set the language -moment.tz.setDefault('Europe/Paris') // set the timezone const { isLocal, isDev } = require('./helpers/env') const Sentry = require('@sentry/node') +moment.locale('fr') // set the language +moment.tz.setDefault('Europe/Paris') // set the timezone + async function onDeleteAccount() { log('info', 'Deleting account ...') log('info', 'Getting secrets ...')