Skip to content
Snippets Groups Projects
Commit 7a9ecb67 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

fix: env variable + add city field

parent 66fd49c0
No related branches found
No related tags found
1 merge request!12Feat/donnes tech debut contrat
......@@ -23,6 +23,9 @@
"postalCode": {
"type": "string"
},
"city": {
"type": "string"
},
"pointId": {
"type": "number"
}
......
function iSLocal() {
return process.env.NODE_ENV === 'development' || process.env.NODE_ENV
return (
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'local'
)
}
module.exports = { iSLocal }
function getAccountId() {
try {
return process.env.NODE_ENV === 'development' ||
process.env.NODE_ENV === 'test'
? 'fakeAccountId'
: JSON.parse(process.env.COZY_FIELDS).account
} catch (err) {
throw new Error(`You must provide 'account' in COZY_FIELDS: ${err.message}`)
}
}
module.exports = { getAccountId }
......@@ -33,7 +33,7 @@ const { verifyContract } = require('./core/contractVerification')
const { terminateContract } = require('./core/contractTermination')
const { getContractStartDate } = require('./core/contractStartDate')
const { getAccount, saveAccountData } = require('./requests/cozy')
const { iSLocal } = require('./helpers/env')
const { getAccountId } = require('./helpers/getAccountId')
moment.locale('fr') // set the language
moment.tz.setDefault('Europe/Paris') // set the timezone
......@@ -48,7 +48,6 @@ let startDailyDateString = startDailyDate.format('YYYY-MM-DD')
const startLoadDate = moment().subtract(7, 'day')
const endDate = moment()
const endDateString = endDate.format('YYYY-MM-DD')
const ACCOUNT_ID = iSLocal() ? 'default_account_id' : 'enedis-sge-grandlyon'
module.exports = new BaseKonnector(start)
......@@ -62,14 +61,14 @@ module.exports = new BaseKonnector(start)
* @param {{secret: fields}} cozyParameters
*/
async function start(fields, cozyParameters) {
log('info', 'Gathering data ...')
log('info', 'Konnector configuration ...')
const ACCOUNT_ID = await getAccountId()
const pointId = fields.pointId
let baseUrl = fields.wso2BaseUrl
let apiAuthKey = fields.apiToken
let contractId = fields.contractId
//TODO switch variable to english
let sgeLogin = fields.sgeLogin
log('info', 'Authenticating ...')
//TODO: Verify if condition is working in local and on build version
if (cozyParameters && Object.keys(cozyParameters).length !== 0) {
log('debug', 'Found COZY_PARAMETERS')
......@@ -95,7 +94,7 @@ async function start(fields, cozyParameters) {
*/
log('info', 'User Logging...')
if (await isFirstStart(await getAccount('default_account_id'))) {
if (await isFirstStart(await getAccount(ACCOUNT_ID))) {
const user = await verifyUserIdentity(fields, baseUrl, apiAuthKey, sgeLogin)
let consent = await createBoConsent(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment