Merge pull request #1652 from siiky/refactor/notifs-rework
LAM-969 LAM-986 LAM-903 refactor: notifications rework
This commit is contained in:
commit
80291637c0
3 changed files with 20 additions and 10 deletions
|
|
@ -20,12 +20,10 @@ const { STALE, PING } = codes
|
|||
const sanctionsNotify = (customer, phone) => {
|
||||
const code = 'SANCTIONS'
|
||||
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 (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))
|
||||
return phone ? addNotif(phone) : customers.getById(customer.id).then(c => addNotif(c.phone))
|
||||
}
|
||||
|
||||
const clearOldCustomerSuspendedNotifications = (customerId, deviceId) => {
|
||||
|
|
|
|||
|
|
@ -53,8 +53,14 @@ const getValidNotifications = (type, detail) => {
|
|||
return db.any(sql, [type, detail]).catch(logger.error)
|
||||
}
|
||||
|
||||
const WITHIN_PAST_WEEK = `created > (CURRENT_TIMESTAMP - INTERVAL '7' DAY)`
|
||||
|
||||
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)
|
||||
}
|
||||
const setRead = (id, read) => {
|
||||
|
|
@ -68,13 +74,21 @@ const markAllAsRead = () => {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
const getAlerts = () => {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,9 @@ const sms = require('./sms')
|
|||
const email = require('./email')
|
||||
const cashOutHelper = require('./cash-out/cash-out-helper')
|
||||
const machineLoader = require('./machine-loader')
|
||||
const customers = require('./customers')
|
||||
const commissionMath = require('./commission-math')
|
||||
const loyalty = require('./loyalty')
|
||||
const transactionBatching = require('./tx-batching')
|
||||
const state = require('./middlewares/state')
|
||||
|
||||
const { CASH_UNIT_CAPACITY, CASH_OUT_DISPENSE_READY, CONFIRMATION_CODE } = require('./constants')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue