feat: server allows to save any amount of accounts
This commit is contained in:
parent
351d2a078b
commit
80cbebecc4
1 changed files with 8 additions and 3 deletions
|
|
@ -21,11 +21,16 @@ const SECRET_FIELDS = [
|
||||||
const accountsSql = `update user_config set data = $2, valid = $3, schema_version = $4 where type = $1;
|
const accountsSql = `update user_config set data = $2, valid = $3, schema_version = $4 where type = $1;
|
||||||
insert into user_config (type, data, valid, schema_version)
|
insert into user_config (type, data, valid, schema_version)
|
||||||
select $1, $2, $3, $4 where $1 not in (select type from user_config)`
|
select $1, $2, $3, $4 where $1 not in (select type from user_config)`
|
||||||
function saveAccounts (accountsToSave) {
|
function saveAccounts (accounts) {
|
||||||
return loadAccounts()
|
return loadAccounts()
|
||||||
.then(currentAccounts => {
|
.then(currentAccounts => {
|
||||||
const serviceCode = _.keys(accountsToSave)[0]
|
const serviceCodes = _.keys(accounts)
|
||||||
accountsToSave[serviceCode] = _.omitBy(_.isEmpty, accountsToSave[serviceCode])
|
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 newAccounts = _.merge(currentAccounts, accountsToSave)
|
||||||
return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue