feat: create cashbox removal notifications

This commit is contained in:
Sérgio Salgado 2021-05-20 14:40:38 +01:00 committed by Josh Harvey
parent 73bd11b38b
commit 598135ccaf
6 changed files with 92 additions and 4 deletions

View file

@ -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
}