From 6c8dec34efd7b0ad354b64a13fb922c2c7e70ec3 Mon Sep 17 00:00:00 2001 From: Teodor Lupu Date: Thu, 6 Oct 2022 17:09:22 +0300 Subject: [PATCH] PharmaLedger-IMI/epi-workspace#930 get network name from environment --- code/scripts/services/SettingsService.js | 36 +++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/code/scripts/services/SettingsService.js b/code/scripts/services/SettingsService.js index 809c9bd..338484a 100644 --- a/code/scripts/services/SettingsService.js +++ b/code/scripts/services/SettingsService.js @@ -31,18 +31,34 @@ export default class SettingsService { } + readSettingFromEnvironment(name, callback) { + require("opendsu").loadApi("config").getEnv(name, callback); + } + initDefaultValues() { - Object.keys(DEFAULT_VALUES).forEach(prop => { - this.readSetting(prop, (err, result) => { - if (err) { - this.writeSetting(prop, DEFAULT_VALUES[prop], (err, record) => { - if (err) { - console.log("Error in settings service constructor. Could not insert record for: ", prop, DEFAULT_VALUES[prop]); - } - }) - } - }) + this.readSettingFromEnvironment("epiDomain", (err, res) => { + if (err) { + console.log("Unable to find key epiDomain in environment file.", err); + writeDefaultValues.call(this); + return; + } + DEFAULT_VALUES.networkName = res; + writeDefaultValues.call(this); }) + + function writeDefaultValues() { + Object.keys(DEFAULT_VALUES).forEach(prop => { + this.readSetting(prop, (err, result) => { + if (err) { + this.writeSetting(prop, DEFAULT_VALUES[prop], (err, record) => { + if (err) { + console.log("Error in settings service constructor. Could not insert record for: ", prop, DEFAULT_VALUES[prop]); + } + }) + } + }) + }) + } } readSetting(property, callback) {