chore: server code formatting

This commit is contained in:
Rafael Taranto 2025-05-12 15:35:00 +01:00
parent aedabcbdee
commit 68517170e2
234 changed files with 9824 additions and 6195 deletions

View file

@ -6,20 +6,24 @@ const customers = require('./customers')
const sanctionStatus = {
loaded: false,
timestamp: null
timestamp: null,
}
const loadOrUpdateSanctions = () => {
if (!sanctionStatus.loaded || (sanctionStatus.timestamp && Date.now() > sanctionStatus.timestamp + T.day)) {
if (
!sanctionStatus.loaded ||
(sanctionStatus.timestamp && Date.now() > sanctionStatus.timestamp + T.day)
) {
logger.info('No sanction lists loaded. Loading sanctions...')
return ofac.load()
return ofac
.load()
.then(() => {
logger.info('OFAC sanction list loaded!')
sanctionStatus.loaded = true
sanctionStatus.timestamp = Date.now()
})
.catch(e => {
logger.error('Couldn\'t load OFAC sanction list!', e)
logger.error("Couldn't load OFAC sanction list!", e)
})
}
@ -27,18 +31,28 @@ const loadOrUpdateSanctions = () => {
}
const checkByUser = (customerId, userToken) => {
return Promise.all([loadOrUpdateSanctions(), customers.getCustomerById(customerId)])
.then(([, customer]) => {
const { firstName, lastName, dateOfBirth } = customer?.idCardData
const birthdate = _.replace(/-/g, '')(dateOfBirth)
const ofacMatches = ofac.match({ firstName, lastName }, birthdate, { threshold: 0.85, fullNameThreshold: 0.95, debug: false })
const isOfacSanctioned = _.size(ofacMatches) > 0
customers.updateCustomer(customerId, { sanctions: !isOfacSanctioned }, userToken)
return { ofacSanctioned: isOfacSanctioned }
return Promise.all([
loadOrUpdateSanctions(),
customers.getCustomerById(customerId),
]).then(([, customer]) => {
const { firstName, lastName, dateOfBirth } = customer.idCardData
const birthdate = _.replace(/-/g, '')(dateOfBirth)
const ofacMatches = ofac.match({ firstName, lastName }, birthdate, {
threshold: 0.85,
fullNameThreshold: 0.95,
debug: false,
})
const isOfacSanctioned = _.size(ofacMatches) > 0
customers.updateCustomer(
customerId,
{ sanctions: !isOfacSanctioned },
userToken,
)
return { ofacSanctioned: isOfacSanctioned }
})
}
module.exports = {
checkByUser
checkByUser,
}