config-util: Use package reload instead of custom reload.

This is a WIP commit to fix the errors while saving settings that occur from
reloadDB function.
This commit is contained in:
Abhigyan Khaund
2018-06-26 11:26:06 +05:30
committed by Akash Nimare
parent 24f5c9b226
commit bb99015fd2

View File

@@ -39,7 +39,12 @@ class ConfigUtil {
}
getConfigItem(key, defaultValue = null) {
this.reloadDB();
try {
this.db.reload();
} catch (err) {
logger.error('Error while reloading settings.json: ');
logger.error(err);
}
const value = this.db.getData('/')[key];
if (value === undefined) {
this.setConfigItem(key, defaultValue);
@@ -50,19 +55,24 @@ class ConfigUtil {
}
// This function returns whether a key exists in the configuration file (settings.json)
isConfigItemExists(key) {
this.reloadDB();
try {
this.db.reload();
} catch (err) {
logger.error('Error while reloading settings.json: ');
logger.error(err);
}
const value = this.db.getData('/')[key];
return (value !== undefined);
}
setConfigItem(key, value) {
this.db.push(`/${key}`, value, true);
this.reloadDB();
this.db.save();
}
removeConfigItem(key) {
this.db.delete(`/${key}`);
this.reloadDB();
this.db.save();
}
reloadDB() {