add cancel script

This commit is contained in:
Josh Harvey 2017-04-17 19:04:10 +03:00
parent 985e3811e3
commit d2700b4eb3
4 changed files with 58 additions and 8 deletions

View file

@ -12,7 +12,8 @@ module.exports = {
post,
monitorLiveIncoming,
monitorStaleIncoming,
monitorUnnotified
monitorUnnotified,
cancel
}
const mapValuesWithKey = _.mapValues.convert({cap: false})
@ -273,3 +274,21 @@ function monitorUnnotified (settings) {
.then(txs => Promise.all(txs.map(notify)))
.catch(logger.error)
}
function cancel (txId) {
const updateRec = {
'dispense_time': 'now()^',
dispense_error: 'Operator cancel',
dispensed: true
}
return Promise.resolve()
.then(() => {
return pgp.helpers.update(updateRec, null, 'cash_out_txs') +
pgp.as.format(' where id=$1', [txId])
})
.then(sql => db.result(sql, false))
.then(res => {
if (res.rowCount !== 1) throw new Error('No such tx-id')
})
}