WIP
This commit is contained in:
parent
b62cd590ef
commit
5312086622
3 changed files with 127 additions and 131 deletions
|
|
@ -41,14 +41,14 @@ exports.init = function init (conString) {
|
|||
}
|
||||
|
||||
// logs inputted bill and overall tx status (if available)
|
||||
exports.recordBill = function recordBill (session, rec) {
|
||||
exports.recordBill = function recordBill (deviceId, rec) {
|
||||
const fields = [
|
||||
'id',
|
||||
'device_fingerprint',
|
||||
'currency_code',
|
||||
'crypto_code',
|
||||
'to_address',
|
||||
'session_id',
|
||||
'tx_id',
|
||||
'device_time',
|
||||
'satoshis',
|
||||
'denomination'
|
||||
|
|
@ -56,11 +56,11 @@ exports.recordBill = function recordBill (session, rec) {
|
|||
|
||||
const values = [
|
||||
rec.uuid,
|
||||
session.fingerprint,
|
||||
deviceId,
|
||||
rec.currency,
|
||||
rec.cryptoCode,
|
||||
rec.toAddress,
|
||||
session.id,
|
||||
rec.txId,
|
||||
rec.deviceTime,
|
||||
rec.cryptoAtoms.toString(),
|
||||
rec.fiat
|
||||
|
|
@ -73,10 +73,10 @@ exports.recordBill = function recordBill (session, rec) {
|
|||
})
|
||||
}
|
||||
|
||||
exports.recordDeviceEvent = function recordDeviceEvent (session, event) {
|
||||
const sql = 'INSERT INTO device_events (device_fingerprint, event_type, ' +
|
||||
exports.recordDeviceEvent = function recordDeviceEvent (deviceId, event) {
|
||||
const sql = 'INSERT INTO device_events (device_id, event_type, ' +
|
||||
'note, device_time) VALUES ($1, $2, $3, $4)'
|
||||
const values = [session.fingerprint, event.eventType, event.note,
|
||||
const values = [deviceId, event.eventType, event.note,
|
||||
event.deviceTime]
|
||||
return db.none(sql, values)
|
||||
}
|
||||
|
|
@ -158,11 +158,11 @@ function insertDispense (session, tx, cartridges) {
|
|||
return db.none(sql, values)
|
||||
}
|
||||
|
||||
exports.addIncomingPhone = function addIncomingPhone (session, tx, notified) {
|
||||
exports.addIncomingPhone = function addIncomingPhone (tx, notified) {
|
||||
const sql = `UPDATE cash_out_txs SET phone=$1, notified=$2
|
||||
WHERE session_id=$3
|
||||
WHERE tx_id=$3
|
||||
AND phone IS NULL`
|
||||
const values = [tx.phone, notified, tx.sessionId]
|
||||
const values = [tx.phone, notified, tx.id]
|
||||
|
||||
return db.result(sql, values)
|
||||
.then(results => {
|
||||
|
|
@ -171,7 +171,7 @@ exports.addIncomingPhone = function addIncomingPhone (session, tx, notified) {
|
|||
|
||||
if (noPhone) return {noPhone: noPhone}
|
||||
|
||||
return db.none(sql2, [tx.sessionId, 'addedPhone'])
|
||||
return db.none(sql2, [tx.txId, 'addedPhone'])
|
||||
.then(() => ({noPhone: noPhone}))
|
||||
})
|
||||
}
|
||||
|
|
@ -244,11 +244,11 @@ exports.addDispense = function addDispense (session, tx, cartridges) {
|
|||
})
|
||||
}
|
||||
|
||||
exports.cartridgeCounts = function cartridgeCounts (session) {
|
||||
exports.cartridgeCounts = function cartridgeCounts (deviceId) {
|
||||
const sql = 'SELECT id, count1, count2 FROM dispenses ' +
|
||||
'WHERE device_fingerprint=$1 AND refill=$2 ' +
|
||||
'ORDER BY id DESC LIMIT 1'
|
||||
return db.oneOrNone(sql, [session.fingerprint, true])
|
||||
return db.oneOrNone(sql, [deviceId, true])
|
||||
.then(row => {
|
||||
const counts = row ? [row.count1, row.count2] : [0, 0]
|
||||
return {id: row.id, counts: counts}
|
||||
|
|
@ -360,14 +360,14 @@ exports.updateTxStatus = function updateTxStatus (tx, status) {
|
|||
})
|
||||
}
|
||||
|
||||
exports.updateRedeem = function updateRedeem (session) {
|
||||
const sql = 'UPDATE cash_out_txs SET redeem=$1 WHERE session_id=$2'
|
||||
const values = [true, session.id]
|
||||
exports.updateRedeem = function updateRedeem (txId) {
|
||||
const sql = 'UPDATE cash_out_txs SET redeem=$1 WHERE txId=$2'
|
||||
const values = [true, txId]
|
||||
|
||||
return db.none(sql, values)
|
||||
.then(() => {
|
||||
const sql2 = 'insert into cash_out_actions (session_id, action) values ($1, $2)'
|
||||
return db.none(sql2, [session.id, 'redeem'])
|
||||
return db.none(sql2, [txId, 'redeem'])
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -382,29 +382,29 @@ exports.updateNotify = function updateNotify (tx) {
|
|||
})
|
||||
}
|
||||
|
||||
function insertCachedRequest (session, path, method, body) {
|
||||
function insertCachedRequest (deviceId, txId, path, method, body) {
|
||||
const fields = [
|
||||
'device_fingerprint',
|
||||
'session_id',
|
||||
'device_id',
|
||||
'tx_id',
|
||||
'path',
|
||||
'method',
|
||||
'body'
|
||||
]
|
||||
|
||||
const sql = getInsertQuery('cached_responses', fields)
|
||||
return db.none(sql, [session.fingerprint, session.id, path, method, body])
|
||||
return db.none(sql, [deviceId, txId, path, method, body])
|
||||
}
|
||||
|
||||
exports.cachedResponse = function (session, path, method) {
|
||||
exports.cachedResponse = function (deviceId, txId, path, method) {
|
||||
const sql = `select body from cached_responses
|
||||
where device_fingerprint=$1
|
||||
and session_id=$2
|
||||
where device_id=$1
|
||||
and tx_id=$2
|
||||
and path=$3
|
||||
and method=$4`
|
||||
|
||||
const values = [session.fingerprint, session.id, path, method]
|
||||
const values = [deviceId, txId, path, method]
|
||||
|
||||
return insertCachedRequest(session, path, method, {pendingRequest: true})
|
||||
return insertCachedRequest(deviceId, txId, path, method, {pendingRequest: true})
|
||||
.then(() => ({}))
|
||||
.catch(err => {
|
||||
if (!isUniqueViolation(err)) throw err
|
||||
|
|
@ -422,15 +422,15 @@ function pruneCachedResponses () {
|
|||
return db.none(sql, values)
|
||||
}
|
||||
|
||||
exports.cacheResponse = function (session, path, method, body) {
|
||||
exports.cacheResponse = function (deviceId, txId, path, method, body) {
|
||||
const sql = `update cached_responses
|
||||
set body=$1
|
||||
where device_fingerprint=$2
|
||||
and session_id=$3
|
||||
where device_id=$2
|
||||
and tx_id=$3
|
||||
and path=$4
|
||||
and method=$5`
|
||||
|
||||
const values = [body, session.fingerprint, session.id, path, method]
|
||||
const values = [body, deviceId, txId, path, method]
|
||||
|
||||
return db.none(sql, values)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue