From ef7f3d519da2882907e12838c1b0a564be080efa Mon Sep 17 00:00:00 2001 From: siiky Date: Wed, 14 Feb 2024 14:53:24 +0000 Subject: [PATCH] refactor: deduplicate `addNotification()` use --- lib/notifier/notificationCenter.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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) => {