improve config saving; fix pairing bug
This commit is contained in:
parent
67e12b19cb
commit
f3f46f7b5b
4 changed files with 81 additions and 9 deletions
|
|
@ -4,6 +4,7 @@ const readFile = pify(fs.readFile)
|
|||
const db = require('./db')
|
||||
const options = require('./options')
|
||||
const logger = require('./logger')
|
||||
const settingsLoader = require('./settings-loader')
|
||||
|
||||
function pullToken (token) {
|
||||
const sql = `delete from pairing_tokens
|
||||
|
|
@ -12,6 +13,26 @@ function pullToken (token) {
|
|||
return db.one(sql, [token])
|
||||
}
|
||||
|
||||
function configureNewDevice (deviceId) {
|
||||
const scope = {crypto: 'global', machine: deviceId}
|
||||
const newFields = [settingsLoader.configAddField(scope, 'cashOutEnabled', false)]
|
||||
|
||||
return settingsLoader.modifyConfig(newFields)
|
||||
}
|
||||
|
||||
function removeDeviceConfig (deviceId) {
|
||||
const scope = {crypto: 'global', machine: deviceId}
|
||||
const newFields = [settingsLoader.configDeleteField(scope, 'cashOutEnabled', false)]
|
||||
|
||||
return settingsLoader.modifyConfig(newFields)
|
||||
}
|
||||
|
||||
function unpair (deviceId) {
|
||||
const sql = 'delete from devices where device_id=$1'
|
||||
return db.none(sql, [deviceId])
|
||||
.then(() => removeDeviceConfig(deviceId))
|
||||
}
|
||||
|
||||
function pair (token, deviceId) {
|
||||
return pullToken(token)
|
||||
.then(r => {
|
||||
|
|
@ -21,7 +42,8 @@ function pair (token, deviceId) {
|
|||
on conflict (device_id)
|
||||
do update set name=$2, paired=TRUE, display=TRUE`
|
||||
|
||||
return db.none(insertSql, [deviceId, r.name])
|
||||
return configureNewDevice(deviceId)
|
||||
.then(() => db.none(insertSql, [deviceId, r.name]))
|
||||
.then(() => true)
|
||||
})
|
||||
.catch(err => {
|
||||
|
|
@ -47,4 +69,4 @@ function isPaired (deviceId) {
|
|||
.then(row => row && row.device_id === deviceId)
|
||||
}
|
||||
|
||||
module.exports = {pair, authorizeCaDownload, isPaired}
|
||||
module.exports = {pair, unpair, authorizeCaDownload, isPaired}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue