Revert "refactor: drop getMachineName() from notifier"
This reverts commit d2cdca701a.
This commit is contained in:
parent
a3b240262a
commit
f220c890a4
2 changed files with 10 additions and 5 deletions
|
|
@ -13,8 +13,6 @@ const smsFuncs = require('./sms')
|
||||||
const webhookFuncs = require('./webhook')
|
const webhookFuncs = require('./webhook')
|
||||||
const { STALE, STALE_STATE } = require('./codes')
|
const { STALE, STALE_STATE } = require('./codes')
|
||||||
|
|
||||||
const { getMachineName } = require('../machine-loader')
|
|
||||||
|
|
||||||
function buildMessage (alerts, notifications) {
|
function buildMessage (alerts, notifications) {
|
||||||
const smsEnabled = utils.isActive(notifications.sms)
|
const smsEnabled = utils.isActive(notifications.sms)
|
||||||
const emailEnabled = utils.isActive(notifications.email)
|
const emailEnabled = utils.isActive(notifications.email)
|
||||||
|
|
@ -160,7 +158,7 @@ function transactionNotify (tx, rec) {
|
||||||
if (!zeroConf && rec.isRedemption) return sendRedemptionMessage(tx.id, rec.error)
|
if (!zeroConf && rec.isRedemption) return sendRedemptionMessage(tx.id, rec.error)
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
getMachineName(tx.deviceId),
|
queries.getMachineName(tx.deviceId),
|
||||||
customerPromise
|
customerPromise
|
||||||
]).then(([machineName, customer]) => {
|
]).then(([machineName, customer]) => {
|
||||||
return utils.buildTransactionMessage(tx, rec, highValueTx, machineName, customer)
|
return utils.buildTransactionMessage(tx, rec, highValueTx, machineName, customer)
|
||||||
|
|
@ -171,7 +169,7 @@ function transactionNotify (tx, rec) {
|
||||||
function complianceNotify (customer, deviceId, action, period) {
|
function complianceNotify (customer, deviceId, action, period) {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
settingsLoader.loadLatest(),
|
settingsLoader.loadLatest(),
|
||||||
getMachineName(deviceId)
|
queries.getMachineName(deviceId)
|
||||||
])
|
])
|
||||||
.then(([settings, machineName]) => {
|
.then(([settings, machineName]) => {
|
||||||
const notifications = configManager.getGlobalNotifications(settings.config)
|
const notifications = configManager.getGlobalNotifications(settings.config)
|
||||||
|
|
@ -269,7 +267,7 @@ function sendTransactionMessage (rec, isHighValueTx) {
|
||||||
function cashboxNotify (deviceId) {
|
function cashboxNotify (deviceId) {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
settingsLoader.loadLatest(),
|
settingsLoader.loadLatest(),
|
||||||
getMachineName(deviceId)
|
queries.getMachineName(deviceId)
|
||||||
])
|
])
|
||||||
.then(([settings, machineName]) => {
|
.then(([settings, machineName]) => {
|
||||||
const notifications = configManager.getGlobalNotifications(settings.config)
|
const notifications = configManager.getGlobalNotifications(settings.config)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,12 @@ compliance - notifications related to warnings triggered by compliance settings
|
||||||
error - notifications related to errors
|
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 addNotification = (type, message, detail) => {
|
||||||
const sql = `INSERT INTO notifications (id, type, message, detail) VALUES ($1, $2, $3, $4)`
|
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)
|
return db.oneOrNone(sql, [uuidv4(), type, message, detail]).catch(logger.error)
|
||||||
|
|
@ -99,4 +105,5 @@ module.exports = {
|
||||||
markAllAsRead,
|
markAllAsRead,
|
||||||
hasUnreadNotifications,
|
hasUnreadNotifications,
|
||||||
getAlerts,
|
getAlerts,
|
||||||
|
getMachineName
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue