new admin structure

This commit is contained in:
Josh Harvey 2017-05-09 00:37:38 +03:00
parent 7d82874916
commit c2282e61b4
17 changed files with 5768 additions and 1204 deletions

View file

@ -13,9 +13,13 @@ function pullToken (token) {
return db.one(sql, [token])
}
function configureNewDevice (deviceId) {
function configureNewDevice (deviceId, machineName, machineModel) {
const scope = {crypto: 'global', machine: deviceId}
const newFields = [settingsLoader.configAddField(scope, 'cashOutEnabled', false)]
const newFields = [
settingsLoader.configAddField(scope, 'cashOutEnabled', false),
settingsLoader.configAddField(scope, 'machineName', machineName),
settingsLoader.configAddField(scope, 'machineModel', machineModel)
]
return settingsLoader.modifyConfig(newFields)
}
@ -33,17 +37,17 @@ function unpair (deviceId) {
.then(() => removeDeviceConfig(deviceId))
}
function pair (token, deviceId) {
function pair (token, deviceId, machineModel) {
return pullToken(token)
.then(r => {
if (r.expired) return false
const insertSql = `insert into devices (device_id, name) values ($1, $2)
const insertSql = `insert into devices (device_id) values ($1)
on conflict (device_id)
do update set name=$2, paired=TRUE, display=TRUE`
do update set paired=TRUE, display=TRUE`
return configureNewDevice(deviceId)
.then(() => db.none(insertSql, [deviceId, r.name]))
return configureNewDevice(deviceId, r.name, machineModel)
.then(() => db.none(insertSql, [deviceId]))
.then(() => true)
})
.catch(err => {