WIPP unpairing

This commit is contained in:
Josh Harvey 2017-03-18 18:49:50 +02:00
parent 134a016bbd
commit e537033319
4 changed files with 226 additions and 4049 deletions

View file

@ -1,4 +1,5 @@
const db = require('../db')
const pairing = require('./pairing')
function getMachines () {
return db.any('select * from devices where display=TRUE order by name')
@ -17,9 +18,20 @@ function resetCashOutBills (rec) {
return db.none(sql, [rec.cassettes[0], rec.cassettes[1], rec.deviceId])
}
function unpair (rec) {
return pairing.unpair(rec.deviceId)
}
function repair (rec) {
return pairing.repair(rec.deviceId)
}
function setMachine (rec) {
switch (rec.action) {
case 'resetCashOutBills': return resetCashOutBills(rec)
case 'unpair': return unpair(rec)
case 'repair': return repair(rec)
default: throw new Error('No such action: ' + rec.action)
}
}

View file

@ -12,6 +12,12 @@ function unpair (deviceId) {
return db.none(sql, [deviceId])
}
function repair (deviceId) {
const sql = 'update devices set paired=TRUE where device_id=$1'
return db.none(sql, [deviceId])
}
function totem (hostname, name) {
const caPath = options.caPath
@ -29,4 +35,4 @@ function totem (hostname, name) {
})
}
module.exports = {totem, unpair}
module.exports = {totem, unpair, repair}

View file

@ -53,7 +53,7 @@ function poll (req, res, next) {
}
const response = {
err: null,
error: null,
locale,
txLimit: config.cashInTransactionLimit,
idVerificationEnabled: config.idVerificationEnabled,
@ -141,7 +141,7 @@ function ca (req, res) {
return pairing.authorizeCaDownload(token)
.then(ca => res.json({ca}))
.catch(() => res.sendStatus(403))
.catch(() => res.status(403).json({error: 'forbidden'}))
}
function pair (req, res, next) {
@ -204,7 +204,7 @@ function filterOldRequests (req, res, next) {
logger.error('Clock skew with lamassu-machine too high [%ss], adjust lamassu-machine clock', (delta / 1000).toFixed(2))
}
if (delta > REQUEST_TTL) return res.status(408).end()
if (delta > REQUEST_TTL) return res.status(408).json({error: 'stale'})
next()
}
@ -218,7 +218,7 @@ function authorize (req, res, next) {
return next()
}
return res.sendStatus(403)
return res.status(403).json({error: 'Forbidden'})
})
.catch(next)
}
@ -265,7 +265,7 @@ app.get('/tx/:id', getTx)
app.get('/tx', getPhoneTx)
app.use(errorHandler)
app.use((req, res) => res.status(404).json({err: 'No such route'}))
app.use((req, res) => res.status(404).json({error: 'No such route'}))
localApp.get('/pid', (req, res) => {
const deviceId = req.query.device_id

File diff suppressed because one or more lines are too long