feat: suspension trigger

This commit is contained in:
Taranto 2020-10-02 16:56:41 +01:00 committed by Josh Harvey
parent 118852a433
commit e0581fc39b
4 changed files with 31 additions and 6 deletions

View file

@ -64,15 +64,18 @@ function cancel (txId) {
})
}
function customerHistory (customerId) {
function customerHistory (customerId, thresholdDays) {
const sql = ` select txIn.id, txIn.created, txIn.fiat, 'cashIn' as direction from cash_in_txs txIn
where txIn.customer_id = $1
and txIn.created > now() - interval $2
union
select txOut.id, txOut.created, txOut.fiat, 'cashOut' as direction from cash_out_txs txOut
where txOut.customer_id = $1
and txOut.created > now() - interval $2
order by created;`
return db.any(sql, [customerId])
const days = _.isNil(thresholdDays) ? 0 : thresholdDays
return db.any(sql, [customerId, `${days} days`])
}
module.exports = {post, cancel, customerHistory}