diff --git a/lib/notifier/notificationCenter.js b/lib/notifier/notificationCenter.js index 08007852..c5ac36fd 100644 --- a/lib/notifier/notificationCenter.js +++ b/lib/notifier/notificationCenter.js @@ -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) => { diff --git a/lib/notifier/queries.js b/lib/notifier/queries.js index d89e74fb..5a51e695 100644 --- a/lib/notifier/queries.js +++ b/lib/notifier/queries.js @@ -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) } diff --git a/lib/plugins.js b/lib/plugins.js index e10532ba..18aaee5f 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -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')