Merge pull request #872 from SiIky/chore/JbtevlHv/log_through_logger
Log through the logger
This commit is contained in:
commit
1dd8f4ff7e
18 changed files with 66 additions and 42 deletions
|
|
@ -289,7 +289,7 @@ const notifyIfActive = (type, fnName, ...args) => {
|
|||
if (!notificationCenter[fnName]) return Promise.reject(new Error(`Notification function ${fnName} for type ${type} does not exist`))
|
||||
if (!(notificationSettings.active && notificationSettings[type])) return Promise.resolve()
|
||||
return notificationCenter[fnName](...args)
|
||||
}).catch(console.error)
|
||||
}).catch(logger.error)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ const _ = require('lodash/fp')
|
|||
|
||||
const dbm = require('../postgresql_interface')
|
||||
const db = require('../db')
|
||||
const logger = require('../logger')
|
||||
|
||||
// types of notifications able to be inserted into db:
|
||||
/*
|
||||
|
|
@ -17,64 +18,64 @@ 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(console.error)
|
||||
.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(console.error)
|
||||
return db.oneOrNone(sql, [uuidv4(), type, message, detail]).catch(logger.error)
|
||||
}
|
||||
|
||||
const getAllValidNotifications = (type) => {
|
||||
const sql = `SELECT * FROM notifications WHERE type = $1 AND valid = 't'`
|
||||
return db.any(sql, [type]).catch(console.error)
|
||||
return db.any(sql, [type]).catch(logger.error)
|
||||
}
|
||||
|
||||
const invalidateNotification = (detail, type) => {
|
||||
detail = _.omitBy(_.isEmpty, detail)
|
||||
const sql = `UPDATE notifications SET valid = 'f', read = 't' WHERE valid = 't' AND type = $1 AND detail::jsonb @> $2::jsonb`
|
||||
return db.none(sql, [type, detail]).catch(console.error).catch(console.error)
|
||||
return db.none(sql, [type, detail]).catch(logger.error)
|
||||
}
|
||||
|
||||
const batchInvalidate = (ids) => {
|
||||
const formattedIds = _.map(pgp.as.text, ids).join(',')
|
||||
const sql = `UPDATE notifications SET valid = 'f', read = 't' WHERE id IN ($1^)`
|
||||
return db.none(sql, [formattedIds]).catch(console.error)
|
||||
return db.none(sql, [formattedIds]).catch(logger.error)
|
||||
}
|
||||
|
||||
const clearBlacklistNotification = (cryptoCode, cryptoAddress) => {
|
||||
const sql = `UPDATE notifications SET valid = 'f', read = 't' WHERE type = 'compliance' AND detail->>'cryptoCode' = $1 AND detail->>'cryptoAddress' = $2 AND (detail->>'code' = 'BLOCKED' OR detail->>'code' = 'REUSED')`
|
||||
return db.none(sql, [cryptoCode, cryptoAddress]).catch(console.error)
|
||||
return db.none(sql, [cryptoCode, cryptoAddress]).catch(logger.error)
|
||||
}
|
||||
|
||||
const getValidNotifications = (type, detail) => {
|
||||
const sql = `SELECT * FROM notifications WHERE type = $1 AND valid = 't' AND detail @> $2`
|
||||
return db.any(sql, [type, detail]).catch(console.error)
|
||||
return db.any(sql, [type, detail]).catch(logger.error)
|
||||
}
|
||||
|
||||
const getNotifications = () => {
|
||||
const sql = `SELECT * FROM notifications ORDER BY created DESC`
|
||||
return db.any(sql).catch(console.error)
|
||||
return db.any(sql).catch(logger.error)
|
||||
}
|
||||
const setRead = (id, read) => {
|
||||
const sql = `UPDATE notifications SET read = $1 WHERE id = $2`
|
||||
return db.none(sql, [read, id]).catch(console.error)
|
||||
return db.none(sql, [read, id]).catch(logger.error)
|
||||
}
|
||||
|
||||
const markAllAsRead = () => {
|
||||
const sql = `UPDATE notifications SET read = 't'`
|
||||
return db.none(sql).catch(console.error)
|
||||
return db.none(sql).catch(logger.error)
|
||||
}
|
||||
|
||||
const hasUnreadNotifications = () => {
|
||||
const sql = `SELECT EXISTS (SELECT 1 FROM notifications WHERE read = 'f' LIMIT 1)`
|
||||
return db.oneOrNone(sql).then(res => res.exists).catch(console.error)
|
||||
return db.oneOrNone(sql).then(res => res.exists).catch(logger.error)
|
||||
}
|
||||
|
||||
const getAlerts = () => {
|
||||
const types = ['fiatBalance', 'cryptoBalance', 'error']
|
||||
const sql = `SELECT * FROM notifications WHERE valid = 't' AND type IN ($1:list) ORDER BY created DESC`
|
||||
return db.any(sql, [types]).catch(console.error)
|
||||
return db.any(sql, [types]).catch(logger.error)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue