WIP
This commit is contained in:
parent
3d9c95ba7f
commit
2e584c558d
3 changed files with 23 additions and 11 deletions
|
|
@ -785,14 +785,12 @@ exports.fetchPhoneTx = function fetchPhoneTx (phone) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchTx = db.fetchTx
|
|
||||||
|
|
||||||
exports.requestDispense = function requestDispense (tx) {
|
exports.requestDispense = function requestDispense (tx) {
|
||||||
return db.addDispenseRequest(tx)
|
return db.addDispenseRequest(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.fetchTx = db.fetchTx
|
||||||
exports.cachedResponse = db.cachedResponse
|
exports.cachedResponse = db.cachedResponse
|
||||||
|
|
||||||
exports.cacheResponse = db.cacheResponse
|
exports.cacheResponse = db.cacheResponse
|
||||||
|
|
||||||
function sweepHD (row) {
|
function sweepHD (row) {
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ exports.addDispenseRequest = function addDispenseRequest (tx) {
|
||||||
const sql2 = 'insert into cash_out_actions (cash_out_txs_id, action) values ($1, $2)'
|
const sql2 = 'insert into cash_out_actions (cash_out_txs_id, action) values ($1, $2)'
|
||||||
|
|
||||||
return db.none(sql2, [tx.id, 'dispenseRequested'])
|
return db.none(sql2, [tx.id, 'dispenseRequested'])
|
||||||
.then(() => ({dispense: true}))
|
.then(() => ({dispense: true, txId: tx.id}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -408,6 +408,7 @@ exports.cachedResponse = function (deviceId, txId, path, method) {
|
||||||
.then(() => ({}))
|
.then(() => ({}))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (!isUniqueViolation(err)) throw err
|
if (!isUniqueViolation(err)) throw err
|
||||||
|
console.log('DEBUG22: %j', err)
|
||||||
return db.one(sql, values)
|
return db.one(sql, values)
|
||||||
.then(row => ({body: row.body}))
|
.then(row => ({body: row.body}))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -285,25 +285,38 @@ function waitForDispense (req, res) {
|
||||||
|
|
||||||
function dispense (req, res) {
|
function dispense (req, res) {
|
||||||
const tx = req.body.tx
|
const tx = req.body.tx
|
||||||
|
const txId = tx.id
|
||||||
const deviceId = getDeviceId(req)
|
const deviceId = getDeviceId(req)
|
||||||
|
|
||||||
return cachedResponse(deviceId, tx.id, req)
|
console.log('DEBUG17')
|
||||||
.then(r => {
|
|
||||||
|
return cachedResponse(deviceId, txId, req)
|
||||||
|
.then(cached => {
|
||||||
|
console.log('DEBUG18: %j', cached)
|
||||||
|
|
||||||
// Cache hit
|
// Cache hit
|
||||||
if (r.body && r.body.pendingRequest) return res.sendStatus(409)
|
if (cached && cached.pendingRequest) return res.sendStatus(409)
|
||||||
if (r.body) res.json(r.body)
|
console.log('DEBUG18.5')
|
||||||
|
if (cached) res.json(cached)
|
||||||
|
|
||||||
|
console.log('DEBUG19')
|
||||||
|
|
||||||
// No cache hit
|
// No cache hit
|
||||||
return plugins.requestDispense(tx)
|
return plugins.requestDispense(tx)
|
||||||
.then(r => {
|
.then(dispenseRec => {
|
||||||
return cacheResponse(req, r)
|
console.log('DEBUG20: %j', dispenseRec)
|
||||||
.then(() => res.json(r))
|
|
||||||
|
return cacheResponse(deviceId, txId, req, dispenseRec)
|
||||||
|
.then(() => res.json(dispenseRec))
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
console.log('DEBUG21')
|
||||||
|
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
res.sendStatus(500)
|
res.sendStatus(500)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.catch(err => logger.error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
function init (localConfig) {
|
function init (localConfig) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue