feat: downloadable tx summary and logs
This commit is contained in:
parent
bd9615c5ea
commit
92b6093a07
7 changed files with 311 additions and 37 deletions
|
|
@ -5,17 +5,17 @@ const transactions = require('../../services/transactions')
|
|||
const anonymous = require('../../../constants').anonymousCustomer
|
||||
|
||||
const transactionsLoader = new DataLoader(ids => transactions.getCustomerTransactionsBatch(ids))
|
||||
const tx_logFields = ["txClass", "id", "deviceId", "toAddress", "cryptoAtoms",
|
||||
"cryptoCode", "fiat", "fiatCode", "fee", "status",
|
||||
"dispense", "notified", "redeem", "phone", "error",
|
||||
"created", "confirmedAt", "hdIndex", "swept", "timedout",
|
||||
"dispenseConfirmed", "provisioned1", "provisioned2",
|
||||
"denomination1", "denomination2", "errorCode", "customerId",
|
||||
"txVersion", "publishedAt", "termsAccepted", "layer2Address",
|
||||
"commissionPercentage", "rawTickerPrice", "receivedCryptoAtoms",
|
||||
"discount", "txHash", "customerPhone", "customerIdCardDataNumber",
|
||||
"customerIdCardDataExpiration", "customerIdCardData", "customerName",
|
||||
"customerFrontCameraPath", "customerIdCardPhotoPath", "expired", "machineName"]
|
||||
const txLogFields = ['txClass', 'id', 'deviceId', 'toAddress', 'cryptoAtoms',
|
||||
'cryptoCode', 'fiat', 'fiatCode', 'fee', 'status',
|
||||
'dispense', 'notified', 'redeem', 'phone', 'error',
|
||||
'created', 'confirmedAt', 'hdIndex', 'swept', 'timedout',
|
||||
'dispenseConfirmed', 'provisioned1', 'provisioned2',
|
||||
'denomination1', 'denomination2', 'errorCode', 'customerId',
|
||||
'txVersion', 'publishedAt', 'termsAccepted', 'layer2Address',
|
||||
'commissionPercentage', 'rawTickerPrice', 'receivedCryptoAtoms',
|
||||
'discount', 'txHash', 'customerPhone', 'customerIdCardDataNumber',
|
||||
'customerIdCardDataExpiration', 'customerIdCardData', 'customerName',
|
||||
'customerFrontCameraPath', 'customerIdCardPhotoPath', 'expired', 'machineName']
|
||||
|
||||
const resolvers = {
|
||||
Customer: {
|
||||
|
|
@ -28,7 +28,11 @@ const resolvers = {
|
|||
transactions: (...[, { from, until, limit, offset, deviceId }]) =>
|
||||
transactions.batch(from, until, limit, offset, deviceId),
|
||||
transactionsCsv: (...[, { from, until, limit, offset }]) =>
|
||||
transactions.batch(from, until, limit, offset).then(data => parseAsync(data, {fields: tx_logFields}))
|
||||
transactions.batch(from, until, limit, offset).then(data => parseAsync(data, { fields: txLogFields })),
|
||||
transactionCsv: (...[, { id, txClass }]) =>
|
||||
transactions.getTx(id, txClass).then(parseAsync),
|
||||
txAssociatedDataCsv: (...[, { id, txClass }]) =>
|
||||
transactions.getTxAssociatedData(id, txClass).then(parseAsync)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ const typeDef = gql`
|
|||
type Query {
|
||||
transactions(from: Date, until: Date, limit: Int, offset: Int, deviceId: ID): [Transaction] @auth
|
||||
transactionsCsv(from: Date, until: Date, limit: Int, offset: Int): String @auth
|
||||
transactionCsv(id: ID, txClass: String): String @auth
|
||||
txAssociatedDataCsv(id: ID, txClass: String): String @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -162,4 +162,33 @@ function cancel (txId) {
|
|||
.then(() => single(txId))
|
||||
}
|
||||
|
||||
module.exports = { batch, single, cancel, getCustomerTransactionsBatch }
|
||||
function getTx (txId, txClass) {
|
||||
const cashInSql = `select 'cashIn' as tx_class, txs.*,
|
||||
((not txs.send_confirmed) and (txs.created <= now() - interval $1)) as expired
|
||||
from cash_in_txs as txs
|
||||
where txs.id=$2`
|
||||
|
||||
const cashOutSql = `select 'cashOut' as tx_class,
|
||||
txs.*,
|
||||
(extract(epoch from (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $2 as expired
|
||||
from cash_out_txs txs
|
||||
where txs.id=$1`
|
||||
|
||||
if (txClass === 'cashIn') {
|
||||
return db.oneOrNone(cashInSql, [cashInTx.PENDING_INTERVAL, txId])
|
||||
} else {
|
||||
return db.oneOrNone(cashOutSql, [txId, REDEEMABLE_AGE])
|
||||
}
|
||||
}
|
||||
|
||||
function getTxAssociatedData (txId, txClass) {
|
||||
const billsSql = `select 'bills' as bills, b.* from bills b where cash_in_txs_id = $1`
|
||||
const actionsSql = `select 'cash_out_actions' as cash_out_actions, actions.* from cash_out_actions actions where tx_id = $1`
|
||||
if (txClass === 'cashIn') {
|
||||
return db.manyOrNone(billsSql, [txId])
|
||||
} else {
|
||||
return db.manyOrNone(actionsSql, [txId])
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { batch, single, cancel, getCustomerTransactionsBatch, getTx, getTxAssociatedData }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue