feat: create cashbox removal notifications
This commit is contained in:
parent
73bd11b38b
commit
598135ccaf
6 changed files with 92 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ const LOW_CRYPTO_BALANCE = 'LOW_CRYPTO_BALANCE'
|
|||
const HIGH_CRYPTO_BALANCE = 'HIGH_CRYPTO_BALANCE'
|
||||
const CASH_BOX_FULL = 'CASH_BOX_FULL'
|
||||
const LOW_CASH_OUT = 'LOW_CASH_OUT'
|
||||
const SECURITY = 'SECURITY'
|
||||
|
||||
const CODES_DISPLAY = {
|
||||
PING: 'Machine Down',
|
||||
|
|
@ -13,7 +14,8 @@ const CODES_DISPLAY = {
|
|||
LOW_CRYPTO_BALANCE: 'Low Crypto Balance',
|
||||
HIGH_CRYPTO_BALANCE: 'High Crypto Balance',
|
||||
CASH_BOX_FULL: 'Cash box full',
|
||||
LOW_CASH_OUT: 'Low Cash-out'
|
||||
LOW_CASH_OUT: 'Low Cash-out',
|
||||
CASHBOX_REMOVED: 'Cashbox removed'
|
||||
}
|
||||
|
||||
const NETWORK_DOWN_TIME = 1 * T.minute
|
||||
|
|
@ -26,7 +28,8 @@ const NOTIFICATION_TYPES = {
|
|||
FIAT_BALANCE: 'fiatBalance',
|
||||
CRYPTO_BALANCE: 'cryptoBalance',
|
||||
COMPLIANCE: 'compliance',
|
||||
ERROR: 'error'
|
||||
ERROR: 'error',
|
||||
SECURITY: 'security'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
@ -36,6 +39,7 @@ module.exports = {
|
|||
HIGH_CRYPTO_BALANCE,
|
||||
CASH_BOX_FULL,
|
||||
LOW_CASH_OUT,
|
||||
SECURITY,
|
||||
CODES_DISPLAY,
|
||||
NETWORK_DOWN_TIME,
|
||||
STALE_STATE,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ const {
|
|||
LOW_CRYPTO_BALANCE,
|
||||
HIGH_CRYPTO_BALANCE,
|
||||
CASH_BOX_FULL,
|
||||
LOW_CASH_OUT
|
||||
LOW_CASH_OUT,
|
||||
SECURITY
|
||||
} = require('./codes')
|
||||
|
||||
function alertSubject (alertRec, config) {
|
||||
|
|
@ -79,6 +80,8 @@ function emailAlert (alert) {
|
|||
return `Cash box full on ${alert.machineName} [${alert.notes} banknotes]`
|
||||
case LOW_CASH_OUT:
|
||||
return `Cassette for ${alert.denomination} ${alert.fiatCode} low [${alert.notes} banknotes]`
|
||||
case SECURITY:
|
||||
return `Cashbox removed on ${alert.machineName}`
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -246,6 +246,41 @@ function sendTransactionMessage (rec, isHighValueTx) {
|
|||
})
|
||||
}
|
||||
|
||||
function cashboxNotify (deviceId) {
|
||||
return Promise.all([
|
||||
settingsLoader.loadLatest(),
|
||||
queries.getMachineName(deviceId)
|
||||
])
|
||||
.then(([settings, machineName]) => {
|
||||
const notifications = configManager.getGlobalNotifications(settings.config)
|
||||
const rec = {
|
||||
sms: {
|
||||
body: `Cashbox removed - ${machineName}`
|
||||
},
|
||||
email: {
|
||||
subject: `Cashbox removal`,
|
||||
body: `Cashbox removed in machine ${machineName}`
|
||||
}
|
||||
}
|
||||
|
||||
const promises = []
|
||||
|
||||
const emailActive =
|
||||
notifications.email.active &&
|
||||
notifications.email.security
|
||||
|
||||
const smsActive =
|
||||
notifications.sms.active &&
|
||||
notifications.sms.security
|
||||
|
||||
if (emailActive) promises.push(emailFuncs.sendMessage(settings, rec))
|
||||
if (smsActive) promises.push(smsFuncs.sendMessage(settings, rec))
|
||||
notifyIfActive('security', 'cashboxNotify', deviceId)
|
||||
|
||||
return Promise.all(promises)
|
||||
})
|
||||
}
|
||||
|
||||
// for notification center, check if type of notification is active before calling the respective notify function
|
||||
const notifyIfActive = (type, fnName, ...args) => {
|
||||
return settingsLoader.loadLatest().then(settings => {
|
||||
|
|
@ -263,5 +298,6 @@ module.exports = {
|
|||
checkPings,
|
||||
checkStuckScreen,
|
||||
sendRedemptionMessage,
|
||||
cashboxNotify,
|
||||
notifyIfActive
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ const codes = require('./codes')
|
|||
const customers = require('../customers')
|
||||
|
||||
const { NOTIFICATION_TYPES: {
|
||||
SECURITY,
|
||||
COMPLIANCE,
|
||||
CRYPTO_BALANCE,
|
||||
FIAT_BALANCE,
|
||||
|
|
@ -177,11 +178,18 @@ const blacklistNotify = (tx, isAddressReuse) => {
|
|||
return queries.addNotification(COMPLIANCE, message, detailB)
|
||||
}
|
||||
|
||||
const cashboxNotify = deviceId => {
|
||||
const detailB = utils.buildDetail({ deviceId: deviceId })
|
||||
const message = `Cashbox removed`
|
||||
return queries.addNotification(SECURITY, message, detailB)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sanctionsNotify,
|
||||
customerComplianceNotify,
|
||||
balancesNotify,
|
||||
errorAlertsNotify,
|
||||
notifCenterTransactionNotify,
|
||||
blacklistNotify
|
||||
blacklistNotify,
|
||||
cashboxNotify
|
||||
}
|
||||
|
|
|
|||
35
migrations/1621430588944-notify-cashbox-removal.js
Normal file
35
migrations/1621430588944-notify-cashbox-removal.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
const db = require('./db')
|
||||
const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
|
||||
|
||||
exports.up = function (next) {
|
||||
const sql = [
|
||||
`ALTER TYPE notification_type ADD VALUE 'security'`
|
||||
]
|
||||
|
||||
return loadLatest()
|
||||
.then(config => {
|
||||
const newConfig = {}
|
||||
if(config.notifications_email_active) {
|
||||
newConfig.notifications_email_security = true
|
||||
}
|
||||
if(config.notifications_sms_active) {
|
||||
newConfig.notifications_sms_security = true
|
||||
}
|
||||
if(config.notifications_notificationCenter_active) {
|
||||
newConfig.notifications_notificationCenter_security = true
|
||||
}
|
||||
|
||||
return saveConfig(newConfig)
|
||||
.then(() => db.multi(sql, next))
|
||||
.catch(err => {
|
||||
if (err.message === 'lamassu-server is not configured') {
|
||||
return next()
|
||||
}
|
||||
return next(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.down = function (next) {
|
||||
next()
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ const sizes = {
|
|||
transactions: 184,
|
||||
compliance: 178,
|
||||
errors: 142,
|
||||
security: 152,
|
||||
active: 263
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +58,7 @@ const Row = ({ namespace, forceDisable }) => {
|
|||
<Cell name="transactions" disabled={disabled} />
|
||||
<Cell name="compliance" disabled={disabled} />
|
||||
<Cell name="errors" disabled={disabled} />
|
||||
<Cell name="security" disabled={disabled} />
|
||||
<Cell name="active" disabled={forceDisable} />
|
||||
</Tr>
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue