From 068f68e838c27429443089510b6484bee3c4b796 Mon Sep 17 00:00:00 2001 From: siiky Date: Wed, 27 Mar 2024 14:27:00 +0000 Subject: [PATCH] refactor: give settings object to `complianceNotify` --- lib/notifier/index.js | 9 +++------ lib/routes/customerRoutes.js | 6 ++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/notifier/index.js b/lib/notifier/index.js index ab75d84e..a70c01b1 100644 --- a/lib/notifier/index.js +++ b/lib/notifier/index.js @@ -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 = { diff --git a/lib/routes/customerRoutes.js b/lib/routes/customerRoutes.js index 4f205232..0af25570 100644 --- a/lib/routes/customerRoutes.js +++ b/lib/routes/customerRoutes.js @@ -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)