fix: remove sanction loader middleware

This commit is contained in:
Sérgio Salgado 2022-07-08 18:17:30 +01:00 committed by Rafael
parent c77fda2623
commit d76e84428f
4 changed files with 30 additions and 37 deletions

View file

@ -1,13 +1,37 @@
const _ = require('lodash/fp')
const logger = require('../../../logger')
const ofac = require('../../../ofac')
const T = require('../../../time')
const sanctionStatus = {
loaded: false,
timestamp: null
}
const loadOrUpdateSanctions = () => {
if (!sanctionStatus.loaded || (sanctionStatus.timestamp && Date.now() > sanctionStatus.timestamp + T.minute)) {
logger.info('No sanction lists loaded. Loading sanctions...')
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!')
})
}
return Promise.resolve()
}
const resolvers = {
Query: {
checkAgainstSanctions: (...[, { firstName, lastName, birthdate }]) => {
const ofacMatches = ofac.match({ firstName, lastName }, birthdate, { threshold: 0.85, fullNameThreshold: 0.95, debug: false })
return { ofacSanctioned: _.size(ofacMatches) > 0 }
}
checkAgainstSanctions: (...[, { firstName, lastName, birthdate }]) => loadOrUpdateSanctions()
.then(() => {
const ofacMatches = ofac.match({ firstName, lastName }, birthdate, { threshold: 0.85, fullNameThreshold: 0.95, debug: false })
return { ofacSanctioned: _.size(ofacMatches) > 0 }
})
}
}