fix redeem bugs

This commit is contained in:
Josh Harvey 2017-04-24 17:28:54 +03:00
parent 91e1077daa
commit dd7d06f38b
4 changed files with 17 additions and 6 deletions

View file

@ -28,7 +28,7 @@ function stateChange (deviceId, deviceTime, rec) {
return dbm.machineEvent(event)
}
function toObj (row) {
function toCashOutTx (row) {
if (!row) return null
const keys = _.keys(row)
@ -44,7 +44,7 @@ function toObj (row) {
newObj[objKey] = row[key]
})
return newObj
return _.set('direction', 'cashOut', newObj)
}
function fetchPhoneTx (phone) {
@ -55,7 +55,7 @@ function fetchPhoneTx (phone) {
const values = [phone, false, TRANSACTION_EXPIRATION]
return db.any(sql, values)
.then(_.map(toObj))
.then(_.map(toCashOutTx))
.then(txs => {
const confirmedTxs = txs.filter(tx => R.contains(tx.status, ['instant', 'confirmed']))
if (confirmedTxs.length > 0) {
@ -75,7 +75,7 @@ function fetchStatusTx (txId, status) {
const sql = 'select * from cash_out_txs where id=$1'
return db.oneOrNone(sql, [txId])
.then(toObj)
.then(toCashOutTx)
.then(tx => {
if (!tx) throw httpError('No transaction', 404)
if (tx.status === status) throw httpError('Not Modified', 304)