This commit is contained in:
Josh Harvey 2016-12-08 16:37:50 +02:00
parent c80f92c227
commit df5d9cac89
3 changed files with 65 additions and 58 deletions

View file

@ -4,24 +4,20 @@ const db = require('./db')
let settingsCache
function load () {
return Promise.all([loadConfig(), loadAccounts()])
.then(function ([config, accounts]) {
settingsCache = {
config,
accounts
}
return settingsCache
})
.catch(err => {
settingsCache = undefined
throw err
})
function load (versionId) {
return Promise.all([loadConfig(versionId), loadAccounts()])
.then(([config, accounts]) => ({
config,
accounts
}))
}
function loadConfig () {
return db.oneOrNone('select data from user_config where type=$1', 'config')
function loadConfig (versionId) {
const sql = `select data
from user_config
where versionId=$1 and type=$2`
return db.oneOrNone(sql, [versionId, 'config'])
.then(row => row ? row.data.config : [])
}