Feat: user compliance saving to DB
This commit is contained in:
parent
204e421b3d
commit
2a9e8dadba
7 changed files with 79 additions and 29 deletions
|
|
@ -225,11 +225,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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -269,7 +269,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)
|
||||
})
|
||||
}
|
||||
|
|
@ -289,7 +289,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 => {
|
||||
|
|
@ -299,7 +299,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}]`)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -314,7 +314,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)
|
||||
})
|
||||
}
|
||||
|
|
@ -346,7 +346,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 => {
|
||||
|
|
@ -355,26 +355,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 = {
|
||||
|
|
@ -384,5 +409,6 @@ module.exports = {
|
|||
checkStuckScreen,
|
||||
sendRedemptionMessage,
|
||||
cashCassettesNotify,
|
||||
addBlacklistNotification
|
||||
blacklistNotify,
|
||||
customerComplianceNotify,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,9 +55,16 @@ const getValidNotifications = (type, detail, deviceId = null) => {
|
|||
return db.any(sql, [type, `%${detail}%`, deviceId])
|
||||
}
|
||||
|
||||
const invalidateNotification = (id) => {
|
||||
const sql = `UPDATE notifications SET valid = 'f', read = 't' WHERE id = $1`
|
||||
return db.none(sql, [id])
|
||||
const invalidateNotification = (id, detail = null, deviceId = null) => {
|
||||
let sql = ''
|
||||
if(id) {
|
||||
sql = `UPDATE notifications SET valid = 'f', read = 't' WHERE valid = 't' AND id = $1`
|
||||
}
|
||||
else {
|
||||
sql = `UPDATE notifications SET valid = 'f', read = 't' WHERE valid = 't' AND detail LIKE $2`
|
||||
sql = deviceId ? sql + ' AND device_id = $3' : sql
|
||||
}
|
||||
return db.none(sql, [id, `%${detail}%`, deviceId])
|
||||
}
|
||||
|
||||
const addComplianceNotification = (deviceId, detail, message) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue