-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1749 from RafaelTaranto/backport/ofac-button
LAM-470 backport: OFAC button
- Loading branch information
Showing
9 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const sanctions = require('../../../sanctions') | ||
const authentication = require('../modules/userManagement') | ||
|
||
const resolvers = { | ||
Query: { | ||
checkAgainstSanctions: (...[, { customerId }, context]) => { | ||
const token = authentication.getToken(context) | ||
return sanctions.checkByUser(customerId, token) | ||
} | ||
} | ||
} | ||
|
||
module.exports = resolvers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { gql } = require('apollo-server-express') | ||
|
||
const typeDef = gql` | ||
type SanctionMatches { | ||
ofacSanctioned: Boolean | ||
} | ||
type Query { | ||
checkAgainstSanctions(customerId: ID): SanctionMatches @auth | ||
} | ||
` | ||
|
||
module.exports = typeDef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const _ = require('lodash/fp') | ||
const ofac = require('./ofac') | ||
const T = require('./time') | ||
const logger = require('./logger') | ||
const customers = require('./customers') | ||
|
||
const sanctionStatus = { | ||
loaded: false, | ||
timestamp: null | ||
} | ||
|
||
const loadOrUpdateSanctions = () => { | ||
if (!sanctionStatus.loaded || (sanctionStatus.timestamp && Date.now() > sanctionStatus.timestamp + T.day)) { | ||
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 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 } | ||
}) | ||
} | ||
|
||
module.exports = { | ||
checkByUser | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters