Chore: remove unused code and use lodash
This commit is contained in:
parent
0ec49159e4
commit
ed4e654036
1 changed files with 9 additions and 60 deletions
|
|
@ -65,51 +65,7 @@ function batch (from = new Date(0).toISOString(), until = new Date().toISOString
|
|||
.then(packager)
|
||||
}
|
||||
|
||||
function getCustomerTransactions (customerId) {
|
||||
const packager = _.flow(it => {
|
||||
return it
|
||||
}, _.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
|
||||
|
||||
const cashInSql = `select 'cashIn' as tx_class, txs.*,
|
||||
c.phone as customer_phone,
|
||||
c.id_card_data_number as customer_id_card_data_number,
|
||||
c.id_card_data_expiration as customer_id_card_data_expiration,
|
||||
c.id_card_data as customer_id_card_data,
|
||||
c.name as customer_name,
|
||||
c.front_camera_path as customer_front_camera_path,
|
||||
c.id_card_photo_path as customer_id_card_photo_path,
|
||||
((not txs.send_confirmed) and (txs.created <= now() - interval $2)) as expired
|
||||
from cash_in_txs as txs
|
||||
left outer join customers c on txs.customer_id = c.id
|
||||
where c.id = $1
|
||||
order by created desc limit $3`
|
||||
|
||||
const cashOutSql = `select 'cashOut' as tx_class,
|
||||
txs.*,
|
||||
actions.tx_hash,
|
||||
c.phone as customer_phone,
|
||||
c.id_card_data_number as customer_id_card_data_number,
|
||||
c.id_card_data_expiration as customer_id_card_data_expiration,
|
||||
c.id_card_data as customer_id_card_data,
|
||||
c.name as customer_name,
|
||||
c.front_camera_path as customer_front_camera_path,
|
||||
c.id_card_photo_path as customer_id_card_photo_path,
|
||||
(extract(epoch from (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $3 as expired
|
||||
from cash_out_txs txs
|
||||
inner join cash_out_actions actions on txs.id = actions.tx_id
|
||||
and actions.action = 'provisionAddress'
|
||||
left outer join customers c on txs.customer_id = c.id
|
||||
where c.id = $1
|
||||
order by created desc limit $2`
|
||||
|
||||
return Promise.all([
|
||||
db.any(cashInSql, [customerId, cashInTx.PENDING_INTERVAL, NUM_RESULTS]),
|
||||
db.any(cashOutSql, [customerId, NUM_RESULTS, REDEEMABLE_AGE])
|
||||
])
|
||||
.then(packager)
|
||||
}
|
||||
|
||||
async function getCustomerTransactionsBatch(ids) {
|
||||
function getCustomerTransactionsBatch (ids) {
|
||||
const packager = _.flow(it => {
|
||||
return it
|
||||
}, _.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
|
||||
|
|
@ -146,21 +102,14 @@ async function getCustomerTransactionsBatch(ids) {
|
|||
where c.id::text LIKE ANY ($1)
|
||||
order by created desc limit $2`
|
||||
|
||||
const cashIns = await db.any(cashInSql, [ids, cashInTx.PENDING_INTERVAL, NUM_RESULTS])
|
||||
const cashOuts = await db.any(cashOutSql, [ids, NUM_RESULTS, REDEEMABLE_AGE])
|
||||
const transactions = await packager([...cashIns, ...cashOuts])
|
||||
|
||||
|
||||
const transactionMap = {}
|
||||
transactions.forEach(transaction => {
|
||||
if(!transactionMap[transaction.customerId]) {
|
||||
transactionMap[transaction.customerId] = [transaction]
|
||||
}
|
||||
else {
|
||||
transactionMap[transaction.customerId].push(transaction)
|
||||
}
|
||||
return Promise.all([
|
||||
db.any(cashInSql, [ids, cashInTx.PENDING_INTERVAL, NUM_RESULTS]),
|
||||
db.any(cashOutSql, [ids, NUM_RESULTS, REDEEMABLE_AGE])
|
||||
])
|
||||
.then(packager).then(transactions => {
|
||||
const transactionMap = _.groupBy('customerId', transactions)
|
||||
return ids.map(id => transactionMap[id])
|
||||
})
|
||||
return ids.map(id => transactionMap[id])
|
||||
}
|
||||
|
||||
function single (txId) {
|
||||
|
|
@ -209,4 +158,4 @@ function cancel (txId) {
|
|||
.then(() => single(txId))
|
||||
}
|
||||
|
||||
module.exports = { batch, getCustomerTransactions, single, cancel, getCustomerTransactionsBatch }
|
||||
module.exports = { batch, single, cancel, getCustomerTransactionsBatch }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue