Feat: user compliance saving to DB
This commit is contained in:
parent
705747e9e0
commit
bf8a40026e
2 changed files with 38 additions and 12 deletions
|
|
@ -374,11 +374,11 @@ const cashCassettesNotify = (cassettes, deviceId) => {
|
|||
Promise.all([queries.getUnreadCassetteNotifications(1, deviceId), queries.getUnreadCassetteNotifications(2, deviceId)]).then(res => {
|
||||
if(res[0].length === 0 && cassette1Count < cassette1Threshold) {
|
||||
console.log("Adding fiatBalance alert for cashbox 1 in database - count & threshold: ", cassette1Count, cassette1Threshold )
|
||||
queries.addCashCassetteWarning(1, deviceId)
|
||||
return queries.addCashCassetteWarning(1, deviceId)
|
||||
}
|
||||
if(res[1].length === 0 && cassette2Count < cassette2Threshold) {
|
||||
console.log("Adding fiatBalance alert for cashbox 2 in database - count & threshold: ", cassette2Count, cassette2Threshold )
|
||||
queries.addCashCassetteWarning(2, deviceId)
|
||||
return queries.addCashCassetteWarning(2, deviceId)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -418,7 +418,7 @@ const clearOldCryptoNotifications = (balances) => {
|
|||
return
|
||||
}
|
||||
// if the notification doesn't exist in the new balances object, then it is outdated and is not valid anymore
|
||||
queries.invalidateNotification(notification.id)
|
||||
return queries.invalidateNotification(notification.id)
|
||||
}, notifications)
|
||||
})
|
||||
}
|
||||
|
|
@ -438,7 +438,7 @@ const balancesNotify = (balances) => {
|
|||
}
|
||||
console.log("Adding high balance alert for " + warning.cryptoCode + " - " + warning.fiatBalance.balance)
|
||||
const balance = utils.formatCurrency(warning.fiatBalance.balance, warning.fiatCode)
|
||||
queries.addCryptoBalanceWarning(`${warning.cryptoCode}_${warning.code}`, `High balance in ${warning.cryptoCode} [${balance}]`)
|
||||
return queries.addCryptoBalanceWarning(`${warning.cryptoCode}_${warning.code}`, `High balance in ${warning.cryptoCode} [${balance}]`)
|
||||
})
|
||||
})
|
||||
lowWarnings.forEach(warning => {
|
||||
|
|
@ -448,7 +448,7 @@ const balancesNotify = (balances) => {
|
|||
}
|
||||
console.log("Adding low balance alert for " + warning.cryptoCode + " - " + warning.fiatBalance.balance)
|
||||
const balance = utils.formatCurrency(warning.fiatBalance.balance, warning.fiatCode)
|
||||
queries.addCryptoBalanceWarning(`${warning.cryptoCode}_${warning.code}`, `Low balance in ${warning.cryptoCode} [${balance}]`)
|
||||
return queries.addCryptoBalanceWarning(`${warning.cryptoCode}_${warning.code}`, `Low balance in ${warning.cryptoCode} [${balance}]`)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -463,7 +463,7 @@ const clearOldErrorNotifications = (alerts) => {
|
|||
return
|
||||
}
|
||||
// if the notification doesn't exist, then it is outdated and is not valid anymore
|
||||
queries.invalidateNotification(notification.id)
|
||||
return queries.invalidateNotification(notification.id)
|
||||
}, res)
|
||||
})
|
||||
}
|
||||
|
|
@ -495,7 +495,7 @@ const errorAlertsNotify = (alertRec) => {
|
|||
}
|
||||
console.log("Adding PING alert on database for " + alert.machineName)
|
||||
const message = `Machine down`
|
||||
queries.addErrorNotification(`${PING}_${alert.age ? alert.age : '-1'}`, message, alert.deviceId)
|
||||
return queries.addErrorNotification(`${PING}_${alert.age ? alert.age : '-1'}`, message, alert.deviceId)
|
||||
})
|
||||
case STALE:
|
||||
return queries.getValidNotifications('error', STALE, alert.deviceId).then(res => {
|
||||
|
|
@ -504,26 +504,51 @@ const errorAlertsNotify = (alertRec) => {
|
|||
}
|
||||
console.log("Adding STALE alert on database for " + alert.machineName)
|
||||
const message = `Machine is stuck on ${alert.state} screen`
|
||||
queries.addErrorNotification(STALE, message, alert.deviceId)
|
||||
return queries.addErrorNotification(STALE, message, alert.deviceId)
|
||||
})
|
||||
default:
|
||||
break
|
||||
return
|
||||
}
|
||||
}, alerts)
|
||||
}
|
||||
|
||||
const addBlacklistNotification = (tx, isAddressReuse) => {
|
||||
const blacklistNotify = (tx, isAddressReuse) => {
|
||||
let detail = ''
|
||||
let message = ''
|
||||
if(isAddressReuse) {
|
||||
detail = `${tx.cryptoCode}_REUSED_${tx.toAddress}`
|
||||
message = `Blocked address reuse: ${tx.cryptoCode} ${tx.toAddress.substr(0,10)}...`
|
||||
message = `Blocked reused address: ${tx.cryptoCode} ${tx.toAddress.substr(0,10)}...`
|
||||
} else {
|
||||
detail = `${tx.cryptoCode}_BLOCKED_${tx.toAddress}`
|
||||
message = `Blocked blacklisted address: ${tx.cryptoCode} ${tx.toAddress.substr(0,10)}...`
|
||||
}
|
||||
|
||||
queries.addComplianceNotification(tx.deviceId, detail, message)
|
||||
return queries.addComplianceNotification(tx.deviceId, detail, message)
|
||||
}
|
||||
|
||||
const clearOldCustomerSuspendedNotifications = (customerId, deviceId) => {
|
||||
const detail = `SUSPENDED_${customerId}`
|
||||
return queries.invalidateNotification(null, detail, deviceId)
|
||||
}
|
||||
|
||||
const customerComplianceNotify = (customer, deviceId, prefix, days = null) => {
|
||||
// prefix can be "BLOCKED", "SUSPENDED", etc
|
||||
const detail = `${prefix}_${customer.id}`
|
||||
const date = new Date()
|
||||
if (days) {
|
||||
date.setDate(date.getDate() + days)
|
||||
}
|
||||
const message = prefix === "SUSPENDED" ? `Customer suspended until ${date.toLocaleString()}` : `Customer blocked`
|
||||
|
||||
// we have to clear every notification for this user where the suspension ended before the current date
|
||||
clearOldCustomerSuspendedNotifications(customer.id, deviceId).then(() => {
|
||||
return queries.getValidNotifications('compliance', detail, deviceId)
|
||||
}).then(res => {
|
||||
if (res.length > 0) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
return queries.addComplianceNotification(deviceId, detail, message)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
|||
|
|
@ -324,6 +324,7 @@ function updateCustomer (req, res, next) {
|
|||
}
|
||||
|
||||
function triggerSanctions (req, res, next) {
|
||||
console.log("SANCTIONS TRIGGERED")
|
||||
const id = req.params.id
|
||||
|
||||
customers.getById(id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue