diff --git a/lib/new-settings-loader.js b/lib/new-settings-loader.js index a1cbd243..3e535ca6 100644 --- a/lib/new-settings-loader.js +++ b/lib/new-settings-loader.js @@ -24,14 +24,14 @@ select $1, $2, $3, $4 where $1 not in (select type from user_config)` function saveAccounts (accounts) { return loadAccounts() .then(currentAccounts => { - const serviceCodes = _.keys(accounts) - const filledAccountInfo = _.map(code => { return { [code]: _.omitBy(_.isEmpty, accounts[code]) } }, serviceCodes) - const accountsToSave = _.reduce((result, item) => { - var key = Object.keys(item)[0] - result[key] = item[key] - return result - }, {}, filledAccountInfo) - const newAccounts = _.merge(currentAccounts, accountsToSave) + const emptySecretFields = _.compose( + _.map(_.last), + _.map(_.split('.')), + _.filter(e => _.get(e, accounts) === '') + )(SECRET_FIELDS) + const filledAccountInfo = _.mapValues(_.omit(emptySecretFields), accounts) + + const newAccounts = _.merge(currentAccounts, filledAccountInfo) return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION]) }) }