refactor: give settings object to complianceNotify

This commit is contained in:
siiky 2024-03-27 14:27:00 +00:00
parent 08843ec73a
commit 068f68e838
2 changed files with 7 additions and 8 deletions

View file

@ -166,12 +166,9 @@ function transactionNotify (tx, rec) {
})
}
function complianceNotify (customer, deviceId, action, period) {
return Promise.all([
settingsLoader.loadLatest(),
queries.getMachineName(deviceId)
])
.then(([settings, machineName]) => {
function complianceNotify (settings, customer, deviceId, action, period) {
return queries.getMachineName(deviceId)
.then(machineName => {
const notifications = configManager.getGlobalNotifications(settings.config)
const msgCore = {

View file

@ -101,10 +101,11 @@ function triggerSanctions (req, res, next) {
function triggerBlock (req, res, next) {
const id = req.params.id
const settings = req.settings
customers.update(id, { authorizedOverride: 'blocked' })
.then(customer => {
notifier.complianceNotify(customer, req.deviceId, 'BLOCKED')
notifier.complianceNotify(settings, customer, req.deviceId, 'BLOCKED')
return respond(req, res, { customer })
})
.catch(next)
@ -113,6 +114,7 @@ function triggerBlock (req, res, next) {
function triggerSuspend (req, res, next) {
const id = req.params.id
const triggerId = req.body.triggerId
const settings = req.settings
const triggers = configManager.getTriggers(req.settings.config)
const getSuspendDays = _.compose(_.get('suspensionDays'), _.find(_.matches({ id: triggerId })))
@ -123,7 +125,7 @@ function triggerSuspend (req, res, next) {
customers.update(id, { suspendedUntil: add(suspensionDuration, new Date()) })
.then(customer => {
notifier.complianceNotify(customer, req.deviceId, 'SUSPENDED', days)
notifier.complianceNotify(settings, customer, req.deviceId, 'SUSPENDED', days)
return respond(req, res, { customer })
})
.catch(next)