This commit is contained in:
Josh Harvey 2016-07-30 11:28:23 +03:00
parent 3d9c95ba7f
commit 2e584c558d
3 changed files with 23 additions and 11 deletions

View file

@ -285,25 +285,38 @@ function waitForDispense (req, res) {
function dispense (req, res) {
const tx = req.body.tx
const txId = tx.id
const deviceId = getDeviceId(req)
return cachedResponse(deviceId, tx.id, req)
.then(r => {
console.log('DEBUG17')
return cachedResponse(deviceId, txId, req)
.then(cached => {
console.log('DEBUG18: %j', cached)
// Cache hit
if (r.body && r.body.pendingRequest) return res.sendStatus(409)
if (r.body) res.json(r.body)
if (cached && cached.pendingRequest) return res.sendStatus(409)
console.log('DEBUG18.5')
if (cached) res.json(cached)
console.log('DEBUG19')
// No cache hit
return plugins.requestDispense(tx)
.then(r => {
return cacheResponse(req, r)
.then(() => res.json(r))
.then(dispenseRec => {
console.log('DEBUG20: %j', dispenseRec)
return cacheResponse(deviceId, txId, req, dispenseRec)
.then(() => res.json(dispenseRec))
})
.catch(err => {
console.log('DEBUG21')
logger.error(err)
res.sendStatus(500)
})
})
.catch(err => logger.error(err))
}
function init (localConfig) {