fix: notify db accounts changes and UI score color

This commit is contained in:
José Oliveira 2022-05-04 21:59:30 +01:00
parent 7e2155b3d4
commit 1d1daf991e
2 changed files with 9 additions and 6 deletions

View file

@ -27,10 +27,13 @@ const accountsSql = `update user_config set data = $2, valid = $3, schema_versio
insert into user_config (type, data, valid, schema_version)
select $1, $2, $3, $4 where $1 not in (select type from user_config)`
function saveAccounts (accounts) {
return loadAccounts()
.then(currentAccounts => {
return Promise.all([loadAccounts(), getOperatorId('middleware')])
.then(([currentAccounts, operatorId]) => {
const newAccounts = _.merge(currentAccounts, accounts)
return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.tx(t => {
return t.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(() => t.none('NOTIFY $1:name, $2', ['reload', JSON.stringify({ schema: asyncLocalStorage.getStore().get('schema'), operatorId })]))
}).catch(console.error)
})
}
function resetAccounts (schemaVersion) {