feat: suspension trigger
This commit is contained in:
parent
118852a433
commit
e0581fc39b
4 changed files with 31 additions and 6 deletions
|
|
@ -10,4 +10,8 @@ function hasSanctions (triggers) {
|
|||
return _.some(_.matches({ requirement: 'sanctions' }))(triggers)
|
||||
}
|
||||
|
||||
module.exports = { getBackwardsCompatibleTriggers, hasSanctions }
|
||||
function maxDaysThreshold (triggers) {
|
||||
return _.max(_.map('thresholdDays')(triggers))
|
||||
}
|
||||
|
||||
module.exports = { getBackwardsCompatibleTriggers, hasSanctions, maxDaysThreshold }
|
||||
|
|
@ -215,6 +215,7 @@ function addOrUpdateCustomer (req) {
|
|||
const machineVersion = req.query.version
|
||||
const triggers = configManager.getTriggers(req.settings.config)
|
||||
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
|
||||
const maxDaysThreshold = complianceTriggers.maxDaysThreshold(triggers)
|
||||
|
||||
return customers.get(customerData.phone)
|
||||
.then(customer => {
|
||||
|
|
@ -235,8 +236,7 @@ function addOrUpdateCustomer (req) {
|
|||
return customers.update(customer.id, patch)
|
||||
})
|
||||
}).then(customer => {
|
||||
// TODO new-admin: only get customer history till max needed for triggers
|
||||
return Tx.customerHistory(customer.id)
|
||||
return Tx.customerHistory(customer.id, maxDaysThreshold)
|
||||
.then(result => {
|
||||
customer.txHistory = result
|
||||
return customer
|
||||
|
|
@ -318,7 +318,12 @@ function triggerBlock (req, res, next) {
|
|||
function triggerSuspend (req, res, next) {
|
||||
const id = req.params.id
|
||||
|
||||
customers.update(id, { authorizedOverride: 'blocked' })
|
||||
const triggers = configManager.getTriggers(req.settings.config)
|
||||
const trigger = _.find(_.matches({ id: req.body.triggerId }))(triggers)
|
||||
|
||||
const date = new Date()
|
||||
date.setDate(date.getDate() + trigger.suspensionDays);
|
||||
customers.update(id, { suspendedUntil: date })
|
||||
.then(customer => respond(req, res, { customer }))
|
||||
.catch(next)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
13
migrations/1601649726488-user-suspend.js
Normal file
13
migrations/1601649726488-user-suspend.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const db = require('./db')
|
||||
|
||||
exports.up = function (next) {
|
||||
var sql = [
|
||||
"ALTER TABLE customers ADD COLUMN suspended_until timestamptz"
|
||||
]
|
||||
|
||||
db.multi(sql, next)
|
||||
}
|
||||
|
||||
exports.down = function (next) {
|
||||
next()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue