This commit is contained in:
Josh Harvey 2017-03-15 22:54:40 +02:00
parent b4d8f3cd4c
commit 340b39d47d
9 changed files with 189 additions and 72 deletions

View file

@ -36,7 +36,7 @@ function poll (req, res, next) {
pids[deviceId] = {pid, ts: Date.now()}
pi.pollQueries(deviceTime, req.query)
return pi.pollQueries(deviceTime, req.query)
.then(results => {
const cartridges = results.cartridges
@ -73,15 +73,32 @@ function poll (req, res, next) {
response.idVerificationLimit = config.idVerificationLimit
}
console.log('DEBUG22: %j', response)
return res.json(response)
})
.catch(next)
}
function getTx (req, res, next) {
if (req.query.phone) return helpers.fetchPhoneTx(req.query.phone)
if (req.query.status) return helpers.fetchStatusTx(req.query.status)
throw httpError('Not Found', 404)
console.log('DEBUG333: %s', req.query.status)
if (req.query.status) {
return helpers.fetchStatusTx(req.params.id, req.query.status)
.then(r => res.json(r))
.catch(next)
}
console.log('DEBUG334')
return next(httpError('Not Found', 404))
}
function getPhoneTx (req, res, next) {
if (req.query.phone) {
return helpers.fetchPhoneTx(req.query.phone)
.then(r => res.json(r))
.catch(next)
}
return next(httpError('Not Found', 404))
}
function postTx (req, res, next) {
@ -153,7 +170,7 @@ function phoneCode (req, res, next) {
}
function errorHandler (err, req, res, next) {
const statusCode = err.name === 'HttpError'
const statusCode = err.name === 'HTTPError'
? err.code || 500
: 500
@ -244,7 +261,8 @@ app.post('/verify_transaction', verifyTx)
app.post('/phone_code', phoneCode)
app.post('/tx', postTx)
app.get('/tx', getTx)
app.get('/tx/:id', getTx)
app.get('/tx', getPhoneTx)
app.use(errorHandler)
app.use((req, res) => res.status(404).json({err: 'No such route'}))