format for latest standard

This commit is contained in:
Josh Harvey 2018-03-10 18:59:40 +00:00
parent 4108efd9c7
commit c2af183911
77 changed files with 1697 additions and 1693 deletions

View file

@ -38,43 +38,43 @@ function removeDeviceConfig (deviceId) {
function unpair (deviceId) {
const sql = 'delete from devices where device_id=$1'
return db.none(sql, [deviceId])
.then(() => removeDeviceConfig(deviceId))
.then(() => removeDeviceConfig(deviceId))
}
function pair (token, deviceId, machineModel) {
return pullToken(token)
.then(r => {
if (r.expired) return false
.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, name) values ($1, $2)
on conflict (device_id)
do update set paired=TRUE, display=TRUE`
return configureNewDevice(deviceId, r.name, machineModel)
.then(() => db.none(insertSql, [deviceId, r.name]))
.then(() => true)
})
.catch(err => {
logger.debug(err)
return false
})
return configureNewDevice(deviceId, r.name, machineModel)
.then(() => db.none(insertSql, [deviceId, r.name]))
.then(() => true)
})
.catch(err => {
logger.debug(err)
return false
})
}
function authorizeCaDownload (caToken) {
return pullToken(caToken)
.then(r => {
if (r.expired) throw new Error('Expired')
.then(r => {
if (r.expired) throw new Error('Expired')
const caPath = options.caPath
return readFile(caPath, {encoding: 'utf8'})
})
const caPath = options.caPath
return readFile(caPath, {encoding: 'utf8'})
})
}
function isPaired (deviceId) {
const sql = 'select device_id from devices where device_id=$1 and paired=TRUE'
return db.oneOrNone(sql, [deviceId])
.then(row => row && row.device_id === deviceId)
.then(row => row && row.device_id === deviceId)
}
module.exports = {pair, unpair, authorizeCaDownload, isPaired}