support backwards compat with raqia redeem

This commit is contained in:
Josh Harvey 2016-05-11 17:56:26 +03:00
parent c4cbe0f6bb
commit 8579f2fd2d
3 changed files with 9 additions and 9 deletions

View file

@ -797,8 +797,8 @@ exports.getPhoneCode = function getPhoneCode (phone) {
.then(() => code)
}
exports.updatePhone = function updatePhone (session, tx) {
return db.addIncomingPhone(session, tx)
exports.updatePhone = function updatePhone (session, tx, notified) {
return db.addIncomingPhone(session, tx, notified)
}
exports.registerRedeem = function registerRedeem (session) {

View file

@ -487,14 +487,14 @@ function insertDispense (client, session, tx, cartridges, transactionId, cb) {
client.query(sql, values, cb)
}
exports.addIncomingPhone = function addIncomingPhone (session, tx, cb) {
var sql = 'UPDATE transactions SET phone=$1 ' +
'WHERE incoming=$2 AND device_fingerprint=$3 AND session_id=$4'
exports.addIncomingPhone = function addIncomingPhone (session, tx, notified, cb) {
var sql = 'UPDATE transactions SET phone=$1, notified=$2 ' +
'WHERE incoming=$3 AND device_fingerprint=$4 AND session_id=$5'
return new Promise((resolve, reject) => {
connect(function (cerr, client, done) {
if (cerr) return reject(cerr)
var values = [tx.phone, true, session.fingerprint, session.id]
var values = [tx.phone, notified, true, session.fingerprint, tx.sessionId]
query(client, sql, values, function (err) {
done(err)
if (err) return reject(err)

View file

@ -225,9 +225,9 @@ function pair (req, res) {
}
function phoneCode (req, res) {
console.log('DEBUG10')
var phone = req.body.phone
logger.debug('Phone code requested for: ' + phone)
return plugins.getPhoneCode(phone)
.then(code => res.json({code: code}))
.catch(err => {
@ -238,7 +238,8 @@ function phoneCode (req, res) {
}
function updatePhone (req, res) {
return plugins.updatePhone(session(req), req.body.phone)
const notified = req.query.notified === 'true'
return plugins.updatePhone(session(req), req.body, notified)
.then(code => res.json(200))
.catch(err => {
logger.error(err)
@ -267,7 +268,6 @@ function registerRedeem (req, res) {
function waitForDispense (req, res) {
return plugins.fetchTx(session(req))
.then(tx => {
console.log('%j', tx)
if (!tx) return res.send(404)
if (tx.status === req.query.status) return res.send(304)
res.json({tx: tx})