Add transaction versioning, tx cancellation (#79)

This commit is contained in:
Josh Harvey 2017-08-29 16:08:06 +03:00 committed by GitHub
parent 4a97535dec
commit 500edcf279
15 changed files with 2223 additions and 1468 deletions

View file

@ -150,6 +150,24 @@ app.get('/api/transactions', (req, res, next) => {
.catch(next)
})
app.get('/api/transaction/:id', (req, res, next) => {
return transactions.single(req.params.id)
.then(r => {
if (!r) return res.status(404).send({Error: 'Not found'})
return res.send(r)
})
})
app.patch('/api/transaction/:id', (req, res, next) => {
if (!req.query.cancel) return res.status(400).send({Error: 'Requires cancel'})
return transactions.cancel(req.params.id)
.then(r => {
return res.send(r)
})
.catch(() => res.status(404).send({Error: 'Not found'}))
})
app.use((err, req, res, next) => {
console.error(err)
@ -223,7 +241,6 @@ function establishSocket (ws, token) {
if (!success) return ws.close(1008, 'Authentication error')
const listener = data => {
console.log('DEBUG200: %j', data)
ws.send(JSON.stringify(data))
}
@ -239,8 +256,6 @@ function establishSocket (ws, token) {
}, REAUTHENTICATE_INTERVAL)
socketEmitter.on('message', listener)
console.log('DEBUG120: %j', token)
ws.send('Testing123')
})
}