diff --git a/lib/notifier/index.js b/lib/notifier/index.js index ab75d84e..3178f5ab 100644 --- a/lib/notifier/index.js +++ b/lib/notifier/index.js @@ -13,6 +13,8 @@ const smsFuncs = require('./sms') const webhookFuncs = require('./webhook') const { STALE, STALE_STATE } = require('./codes') +const { getMachineName } = require('../machine-loader') + function buildMessage (alerts, notifications) { const smsEnabled = utils.isActive(notifications.sms) const emailEnabled = utils.isActive(notifications.email) @@ -158,7 +160,7 @@ function transactionNotify (tx, rec) { if (!zeroConf && rec.isRedemption) return sendRedemptionMessage(tx.id, rec.error) return Promise.all([ - queries.getMachineName(tx.deviceId), + getMachineName(tx.deviceId), customerPromise ]).then(([machineName, customer]) => { return utils.buildTransactionMessage(tx, rec, highValueTx, machineName, customer) @@ -169,7 +171,7 @@ function transactionNotify (tx, rec) { function complianceNotify (customer, deviceId, action, period) { return Promise.all([ settingsLoader.loadLatest(), - queries.getMachineName(deviceId) + getMachineName(deviceId) ]) .then(([settings, machineName]) => { const notifications = configManager.getGlobalNotifications(settings.config) @@ -267,7 +269,7 @@ function sendTransactionMessage (rec, isHighValueTx) { function cashboxNotify (deviceId) { return Promise.all([ settingsLoader.loadLatest(), - queries.getMachineName(deviceId) + getMachineName(deviceId) ]) .then(([settings, machineName]) => { const notifications = configManager.getGlobalNotifications(settings.config) diff --git a/lib/notifier/queries.js b/lib/notifier/queries.js index b1e92ab0..2d24eeb2 100644 --- a/lib/notifier/queries.js +++ b/lib/notifier/queries.js @@ -15,12 +15,6 @@ compliance - notifications related to warnings triggered by compliance settings error - notifications related to errors */ -function getMachineName (machineId) { - const sql = 'SELECT * FROM devices WHERE device_id=$1' - return db.oneOrNone(sql, [machineId]) - .then(it => it.name).catch(logger.error) -} - const addNotification = (type, message, detail) => { const sql = `INSERT INTO notifications (id, type, message, detail) VALUES ($1, $2, $3, $4)` return db.oneOrNone(sql, [uuidv4(), type, message, detail]).catch(logger.error) @@ -105,5 +99,4 @@ module.exports = { markAllAsRead, hasUnreadNotifications, getAlerts, - getMachineName }