Splitting up daily volume queries
This commit is contained in:
parent
18bbfc6def
commit
abf4dd5c32
1 changed files with 26 additions and 10 deletions
|
|
@ -117,22 +117,38 @@ function getById (id, userToken) {
|
|||
* @returns {Bignumber} Customer's daily volume
|
||||
*/
|
||||
function getDailyVolume (id, txId) {
|
||||
return Promise.all([
|
||||
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_in_txs
|
||||
where customer_id=$1
|
||||
${txId ? 'and id!=$2' : ''}
|
||||
and created > now() - interval '1 day'`, [id, txId]),
|
||||
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_out_txs
|
||||
where customer_id=$1
|
||||
${txId ? 'and id!=$2' : ''}
|
||||
and created > now() - interval '1 day'`, [id, txId])
|
||||
]).then(([cashIn, cashOut]) => {
|
||||
const queries = txId ? getDailyVolumeMinusCurrentTxQueries(id, txId) : getDailyVolumeQueries(id)
|
||||
return Promise.all(queries).then(([cashIn, cashOut]) => {
|
||||
const dailyVolume = BN(cashIn.total).add(cashOut.total)
|
||||
const hoursTillLimitClear = getHoursTillLimitClear(cashIn.maxdate, cashOut.maxdate)
|
||||
return { dailyVolume, hoursTillLimitClear }
|
||||
})
|
||||
}
|
||||
|
||||
function getDailyVolumeQueries (id) {
|
||||
return [
|
||||
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_in_txs
|
||||
where customer_id=$1
|
||||
and created > now() - interval '1 day'`, [id]),
|
||||
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_out_txs
|
||||
where customer_id=$1
|
||||
and created > now() - interval '1 day'`, [id])
|
||||
]
|
||||
}
|
||||
|
||||
function getDailyVolumeMinusCurrentTxQueries (id, txId) {
|
||||
return [
|
||||
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_in_txs
|
||||
where customer_id=$1
|
||||
and id!=$2
|
||||
and created > now() - interval '1 day'`, [id, txId]),
|
||||
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_out_txs
|
||||
where customer_id=$1
|
||||
and id!=$2
|
||||
and created > now() - interval '1 day'`, [id, txId])
|
||||
]
|
||||
}
|
||||
|
||||
function getHoursTillLimitClear (cashInDate, cashOutDate) {
|
||||
let startDate = moment()
|
||||
startDate = startDate.subtract(1, 'days')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue