refactor: deduplicate addNotification() use

This commit is contained in:
siiky 2024-02-14 14:53:24 +00:00
parent d2cdca701a
commit ef7f3d519d

View file

@ -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) => {