diff --git a/lib/new-admin/graphql/resolvers/transaction.resolver.js b/lib/new-admin/graphql/resolvers/transaction.resolver.js index ebfb8dc5..e41c17f9 100644 --- a/lib/new-admin/graphql/resolvers/transaction.resolver.js +++ b/lib/new-admin/graphql/resolvers/transaction.resolver.js @@ -10,17 +10,6 @@ const anonymous = require('../../../constants').anonymousCustomer const logDateFormat = require('../../../logs').logDateFormat const transactionsLoader = new DataLoader(ids => transactions.getCustomerTransactionsBatch(ids), { cache: false }) -const txLogFields = ['txClass', 'id', 'deviceId', 'toAddress', 'cryptoAtoms', - 'cryptoCode', 'fiat', 'fiatCode', 'fee', 'status', 'fiatProfit', - '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', 'walletScore'] const resolvers = { Customer: { @@ -34,7 +23,7 @@ const resolvers = { transactions.batch(from, until, limit, offset, deviceId, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status, excludeTestingCustomers), transactionsCsv: (...[, { from, until, limit, offset, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status, timezone, excludeTestingCustomers, simplified }]) => transactions.batch(from, until, limit, offset, null, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status, excludeTestingCustomers, simplified) - .then(data => parseAsync(logDateFormat(timezone, data, ['created', 'sendTime']), { fields: txLogFields })), + .then(data => parseAsync(logDateFormat(timezone, data, ['created', 'sendTime']))), transactionCsv: (...[, { id, txClass, timezone }]) => transactions.getTx(id, txClass).then(data => parseAsync(logDateFormat(timezone, [data], ['created', 'sendTime'])) diff --git a/lib/new-admin/services/transactions.js b/lib/new-admin/services/transactions.js index 1f40fe8d..0f111937 100644 --- a/lib/new-admin/services/transactions.js +++ b/lib/new-admin/services/transactions.js @@ -47,7 +47,7 @@ function batch ( toAddress = null, status = null, excludeTestingCustomers = false, - simplified = false + simplified ) { const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addProfits, addNames) @@ -120,13 +120,40 @@ function batch ( .then(packager) .then(res => { if (simplified) return simplifiedBatch(res) - else return res + // GQL transactions and transactionsCsv both use this function and + // if we don't check for the correct simplified value, the Transactions page polling + // will continuously build a csv in the background + else if (simplified === false) return advancedBatch(res) + return res }) } +function advancedBatch (data) { + const fields = ['txClass', 'id', 'deviceId', 'toAddress', 'cryptoAtoms', + 'cryptoCode', 'fiat', 'fiatCode', 'fee', 'status', 'fiatProfit', 'cryptoAmount', + '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', 'walletScore'] + + const addAdvancedFields = _.map(it => ({ + ...it, + status: getStatus(it), + fiatProfit: getProfit(it).toString(), + cryptoAmount: getCryptoAmount(it).toString() + })) + + return _.compose(_.map(_.pick(fields)), addAdvancedFields)(data) +} + function simplifiedBatch (data) { const fields = ['txClass', 'id', 'created', 'machineName', - 'cryptoCode', 'fiat', 'fiatCode', 'phone', 'toAddress', + 'cryptoCode', 'cryptoAtoms', 'fiat', 'fiatCode', 'phone', 'toAddress', 'txHash', 'dispense', 'error', 'status', 'fiatProfit', 'cryptoAmount'] const addSimplifiedFields = _.map(it => ({