new admin structure
This commit is contained in:
parent
7d82874916
commit
c2282e61b4
17 changed files with 5768 additions and 1204 deletions
|
|
@ -103,6 +103,19 @@ function loadLatestConfig () {
|
|||
})
|
||||
}
|
||||
|
||||
function loadRecentConfig () {
|
||||
if (argv.fixture) return loadFixture()
|
||||
|
||||
const sql = `select id, data
|
||||
from user_config
|
||||
where type=$1
|
||||
order by id desc
|
||||
limit 1`
|
||||
|
||||
return db.one(sql, ['config'])
|
||||
.then(row => row.data.config)
|
||||
}
|
||||
|
||||
function loadAccounts () {
|
||||
const toFields = fieldArr => _.fromPairs(_.map(r => [r.code, r.value], fieldArr))
|
||||
const toPairs = r => [r.code, toFields(r.fields)]
|
||||
|
|
@ -152,16 +165,28 @@ function configDeleteField (scope, fieldCode) {
|
|||
}
|
||||
}
|
||||
|
||||
function addEdgeCases (config) {
|
||||
const isCashOutEnabled = r => r.fieldLocator.fieldScope.machine !== 'global' &&
|
||||
r.fieldLocator.code === 'cashOutEnabled' &&
|
||||
r.fieldValue.value
|
||||
|
||||
const cashOutEnabledExists = _.some(isCashOutEnabled, config)
|
||||
const scope = {crypto: 'global', machine: 'global'}
|
||||
const newField = configAddField(scope, 'cashOutEnabled', cashOutEnabledExists)
|
||||
|
||||
return mergeValues(config, newField)
|
||||
}
|
||||
|
||||
function modifyConfig (newFields) {
|
||||
const TransactionMode = pgp.txMode.TransactionMode
|
||||
const isolationLevel = pgp.txMode.isolationLevel
|
||||
const tmSRD = new TransactionMode({tiLevel: isolationLevel.serializable})
|
||||
|
||||
function transaction (t) {
|
||||
return loadLatest()
|
||||
.then(settings => {
|
||||
const oldConfig = settings.config
|
||||
return save(mergeValues(oldConfig, newFields))
|
||||
return loadRecentConfig()
|
||||
.then(oldConfig => {
|
||||
const doSave = _.flow(mergeValues, addEdgeCases, save)
|
||||
return doSave(oldConfig, newFields)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -173,6 +198,7 @@ function modifyConfig (newFields) {
|
|||
module.exports = {
|
||||
settings,
|
||||
loadConfig,
|
||||
loadRecentConfig,
|
||||
load,
|
||||
loadLatest,
|
||||
save,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue