This commit is contained in:
Josh Harvey 2016-12-07 20:14:39 +02:00
parent 2b81dcd0ed
commit 89b7c95c8a
2 changed files with 54 additions and 7 deletions

View file

@ -5,14 +5,11 @@ const db = require('./db')
let settingsCache
function load () {
return Promise.all([
db.one('select data from user_config where type=$1', 'config'),
loadAccounts()
])
.then(function ([data, accounts]) {
return Promise.all([loadConfig(), loadAccounts()])
.then(function ([config, accounts]) {
settingsCache = {
config: data.data.config,
accounts: accounts
config,
accounts
}
return settingsCache
@ -23,6 +20,11 @@ function load () {
})
}
function loadConfig () {
return db.oneOrNone('select data from user_config where type=$1', 'config')
.then(row => row ? row.data.config : [])
}
function loadAccounts () {
const toFields = fieldArr => R.fromPairs(R.map(r => [r.code, r.value], fieldArr))
const toPairs = r => [r.code, toFields(r.fields)]
@ -40,5 +42,6 @@ function settings () {
module.exports = {
settings,
loadConfig,
load
}