Merge pull request #1652 from siiky/refactor/notifs-rework

LAM-969 LAM-986 LAM-903 refactor: notifications rework
This commit is contained in:
Rafael Taranto 2024-03-26 13:47:43 +00:00 committed by GitHub
commit 80291637c0
3 changed files with 20 additions and 10 deletions

View file

@ -20,12 +20,10 @@ const { STALE, PING } = codes
const sanctionsNotify = (customer, phone) => { const sanctionsNotify = (customer, phone) => {
const code = 'SANCTIONS' const code = 'SANCTIONS'
const detailB = utils.buildDetail({ customerId: customer.id, code }) const detailB = utils.buildDetail({ customerId: customer.id, code })
const addNotif = phone =>
queries.addNotification(COMPLIANCE, `Blocked customer with phone ${phone} for being on the OFAC sanctions list`, detailB)
// if it's a new customer then phone comes as undefined // if it's a new customer then phone comes as undefined
if (phone) { return phone ? addNotif(phone) : customers.getById(customer.id).then(c => addNotif(c.phone))
return queries.addNotification(COMPLIANCE, `Blocked customer with phone ${phone} for being on the OFAC sanctions list`, detailB)
}
return customers.getById(customer.id).then(c => queries.addNotification(COMPLIANCE, `Blocked customer with phone ${c.phone} for being on the OFAC sanctions list`, detailB))
} }
const clearOldCustomerSuspendedNotifications = (customerId, deviceId) => { const clearOldCustomerSuspendedNotifications = (customerId, deviceId) => {

View file

@ -53,8 +53,14 @@ const getValidNotifications = (type, detail) => {
return db.any(sql, [type, detail]).catch(logger.error) return db.any(sql, [type, detail]).catch(logger.error)
} }
const WITHIN_PAST_WEEK = `created > (CURRENT_TIMESTAMP - INTERVAL '7' DAY)`
const getNotifications = () => { const getNotifications = () => {
const sql = `SELECT * FROM notifications ORDER BY created DESC` const sql = `
SELECT * FROM notifications
WHERE ${WITHIN_PAST_WEEK}
ORDER BY created DESC
`
return db.any(sql).catch(logger.error) return db.any(sql).catch(logger.error)
} }
const setRead = (id, read) => { const setRead = (id, read) => {
@ -68,13 +74,21 @@ const markAllAsRead = () => {
} }
const hasUnreadNotifications = () => { const hasUnreadNotifications = () => {
const sql = `SELECT EXISTS (SELECT 1 FROM notifications WHERE read = 'f' LIMIT 1)` const sql = `
SELECT EXISTS
(SELECT * FROM notifications
WHERE NOT read AND ${WITHIN_PAST_WEEK})
`
return db.oneOrNone(sql).then(res => res.exists).catch(logger.error) return db.oneOrNone(sql).then(res => res.exists).catch(logger.error)
} }
const getAlerts = () => { const getAlerts = () => {
const types = ['fiatBalance', 'cryptoBalance', 'error'] const types = ['fiatBalance', 'cryptoBalance', 'error']
const sql = `SELECT * FROM notifications WHERE valid = 't' AND type IN ($1:list) ORDER BY created DESC` const sql = `
SELECT * FROM notifications
WHERE ${WITHIN_PAST_WEEK} AND type IN ($1:list)
ORDER BY created DESC
`
return db.any(sql, [types]).catch(logger.error) return db.any(sql, [types]).catch(logger.error)
} }

View file

@ -19,11 +19,9 @@ const sms = require('./sms')
const email = require('./email') const email = require('./email')
const cashOutHelper = require('./cash-out/cash-out-helper') const cashOutHelper = require('./cash-out/cash-out-helper')
const machineLoader = require('./machine-loader') const machineLoader = require('./machine-loader')
const customers = require('./customers')
const commissionMath = require('./commission-math') const commissionMath = require('./commission-math')
const loyalty = require('./loyalty') const loyalty = require('./loyalty')
const transactionBatching = require('./tx-batching') const transactionBatching = require('./tx-batching')
const state = require('./middlewares/state')
const { CASH_UNIT_CAPACITY, CASH_OUT_DISPENSE_READY, CONFIRMATION_CODE } = require('./constants') const { CASH_UNIT_CAPACITY, CASH_OUT_DISPENSE_READY, CONFIRMATION_CODE } = require('./constants')