fix: compliance notifications through sms and email
This commit is contained in:
parent
6537938ec3
commit
129e5555df
2 changed files with 48 additions and 2 deletions
|
|
@ -166,6 +166,51 @@ function transactionNotify (tx, rec) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function complianceNotify (customer, deviceId, ...args) {
|
||||||
|
return Promise.all([
|
||||||
|
settingsLoader.loadLatest(),
|
||||||
|
queries.getMachineName(deviceId)
|
||||||
|
])
|
||||||
|
.then(([settings, machineName]) => {
|
||||||
|
const notifications = configManager.getGlobalNotifications(settings.config)
|
||||||
|
|
||||||
|
const action = args[0]
|
||||||
|
const period = args[1]
|
||||||
|
|
||||||
|
const msgCore = {
|
||||||
|
BLOCKED: `was blocked`,
|
||||||
|
SUSPENDED: `was suspended for ${!!period && period} days`
|
||||||
|
}
|
||||||
|
|
||||||
|
const rec = {
|
||||||
|
sms: {
|
||||||
|
body: `Customer ${customer.phone} ${msgCore[action]} - ${machineName}`
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
subject: `Customer compliance`,
|
||||||
|
body: `Customer ${customer.phone} ${msgCore[action]} in machine ${machineName}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const promises = []
|
||||||
|
|
||||||
|
const emailActive =
|
||||||
|
notifications.email.active &&
|
||||||
|
notifications.email.compliance
|
||||||
|
|
||||||
|
const smsActive =
|
||||||
|
notifications.sms.active &&
|
||||||
|
notifications.sms.compliance
|
||||||
|
|
||||||
|
if (emailActive) promises.push(emailFuncs.sendMessage(settings, rec))
|
||||||
|
if (smsActive) promises.push(smsFuncs.sendMessage(settings, rec))
|
||||||
|
|
||||||
|
notifyIfActive('compliance', 'customerComplianceNotify', customer, deviceId, ...args)
|
||||||
|
|
||||||
|
return Promise.all(promises)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function sendRedemptionMessage (txId, error) {
|
function sendRedemptionMessage (txId, error) {
|
||||||
const subject = `Here's an update on transaction ${txId}`
|
const subject = `Here's an update on transaction ${txId}`
|
||||||
const body = error
|
const body = error
|
||||||
|
|
@ -216,6 +261,7 @@ const notifyIfActive = (type, fnName, ...args) => {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
transactionNotify,
|
transactionNotify,
|
||||||
|
complianceNotify,
|
||||||
checkNotification,
|
checkNotification,
|
||||||
checkPings,
|
checkPings,
|
||||||
checkStuckScreen,
|
checkStuckScreen,
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ function triggerBlock (req, res, next) {
|
||||||
|
|
||||||
customers.update(id, { authorizedOverride: 'blocked' })
|
customers.update(id, { authorizedOverride: 'blocked' })
|
||||||
.then(customer => {
|
.then(customer => {
|
||||||
notifier.notifyIfActive('compliance', 'customerComplianceNotify', customer, req.deviceId, 'BLOCKED')
|
notifier.complianceNotify(customer, req.deviceId, 'BLOCKED')
|
||||||
return respond(req, res, { customer })
|
return respond(req, res, { customer })
|
||||||
})
|
})
|
||||||
.catch(next)
|
.catch(next)
|
||||||
|
|
@ -80,7 +80,7 @@ function triggerSuspend (req, res, next) {
|
||||||
date.setDate(date.getDate() + days)
|
date.setDate(date.getDate() + days)
|
||||||
customers.update(id, { suspendedUntil: date })
|
customers.update(id, { suspendedUntil: date })
|
||||||
.then(customer => {
|
.then(customer => {
|
||||||
notifier.notifyIfActive('compliance', 'customerComplianceNotify', customer, req.deviceId, 'SUSPENDED', days)
|
notifier.complianceNotify(customer, req.deviceId, 'SUSPENDED', days)
|
||||||
return respond(req, res, { customer })
|
return respond(req, res, { customer })
|
||||||
})
|
})
|
||||||
.catch(next)
|
.catch(next)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue