chore: server code formatting
This commit is contained in:
parent
aedabcbdee
commit
68517170e2
234 changed files with 9824 additions and 6195 deletions
|
|
@ -5,75 +5,87 @@ const logger = require('./logger')
|
|||
const db = require('./db')
|
||||
const ofac = require('./ofac/index')
|
||||
|
||||
function logSanctionsMatch (deviceId, customer, sanctionsId, alias) {
|
||||
function logSanctionsMatch(deviceId, customer, sanctionsId, alias) {
|
||||
const sql = `insert into sanctions_logs
|
||||
(id, device_id, sanctioned_id, sanctioned_alias_id, sanctioned_alias_full_name, customer_id)
|
||||
values
|
||||
($1, $2, $3, $4, $5, $6)`
|
||||
|
||||
return db.none(sql, [uuid.v4(), deviceId, sanctionsId, alias.id, alias.fullName, customer.id])
|
||||
return db.none(sql, [
|
||||
uuid.v4(),
|
||||
deviceId,
|
||||
sanctionsId,
|
||||
alias.id,
|
||||
alias.fullName,
|
||||
customer.id,
|
||||
])
|
||||
}
|
||||
|
||||
function logSanctionsMatches (deviceId, customer, results) {
|
||||
const logAlias = resultId => alias => logSanctionsMatch(deviceId, customer, resultId, alias)
|
||||
function logSanctionsMatches(deviceId, customer, results) {
|
||||
const logAlias = resultId => alias =>
|
||||
logSanctionsMatch(deviceId, customer, resultId, alias)
|
||||
const logResult = result => _.map(logAlias(result.id), result.aliases)
|
||||
|
||||
return Promise.all(_.flatMap(logResult, results))
|
||||
}
|
||||
|
||||
function matchOfac (deviceId, customer) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
// Probably because we haven't asked for ID yet
|
||||
if (!_.isPlainObject(customer.idCardData)) {
|
||||
return true
|
||||
}
|
||||
function matchOfac(deviceId, customer) {
|
||||
return Promise.resolve().then(() => {
|
||||
// Probably because we haven't asked for ID yet
|
||||
if (!_.isPlainObject(customer.idCardData)) {
|
||||
return true
|
||||
}
|
||||
|
||||
const nameParts = {
|
||||
firstName: customer.idCardData.firstName,
|
||||
lastName: customer.idCardData.lastName
|
||||
}
|
||||
const nameParts = {
|
||||
firstName: customer.idCardData.firstName,
|
||||
lastName: customer.idCardData.lastName,
|
||||
}
|
||||
|
||||
if (_.some(_.isNil, _.values(nameParts))) {
|
||||
logger.error(new Error(`Insufficient idCardData while matching OFAC for: ${customer.id}`))
|
||||
return true
|
||||
}
|
||||
if (_.some(_.isNil, _.values(nameParts))) {
|
||||
logger.error(
|
||||
new Error(
|
||||
`Insufficient idCardData while matching OFAC for: ${customer.id}`,
|
||||
),
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
const birthDate = customer.idCardData.dateOfBirth
|
||||
const birthDate = customer.idCardData.dateOfBirth
|
||||
|
||||
if (_.isNil(birthDate)) {
|
||||
logger.error(new Error(`No birth date while matching OFAC for: ${customer.id}`))
|
||||
return true
|
||||
}
|
||||
if (_.isNil(birthDate)) {
|
||||
logger.error(
|
||||
new Error(`No birth date while matching OFAC for: ${customer.id}`),
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
const options = {
|
||||
threshold: 0.85,
|
||||
fullNameThreshold: 0.95,
|
||||
debug: false
|
||||
}
|
||||
const options = {
|
||||
threshold: 0.85,
|
||||
fullNameThreshold: 0.95,
|
||||
debug: false,
|
||||
}
|
||||
|
||||
const results = ofac.match(nameParts, birthDate, options)
|
||||
const results = ofac.match(nameParts, birthDate, options)
|
||||
|
||||
return logSanctionsMatches(deviceId, customer, results)
|
||||
.then(() => !_.isEmpty(results))
|
||||
})
|
||||
return logSanctionsMatches(deviceId, customer, results).then(
|
||||
() => !_.isEmpty(results),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function validateOfac (deviceId, customer) {
|
||||
function validateOfac(deviceId, customer) {
|
||||
if (customer.sanctionsOverride === 'blocked') return Promise.resolve(false)
|
||||
if (customer.sanctionsOverride === 'verified') return Promise.resolve(true)
|
||||
|
||||
return matchOfac(deviceId, customer)
|
||||
.then(didMatch => !didMatch)
|
||||
return matchOfac(deviceId, customer).then(didMatch => !didMatch)
|
||||
}
|
||||
|
||||
function validationPatch (deviceId, customer) {
|
||||
return validateOfac(deviceId, customer)
|
||||
.then(sanctions =>
|
||||
_.isNil(customer.sanctions) || customer.sanctions !== sanctions ?
|
||||
{ sanctions } :
|
||||
{}
|
||||
)
|
||||
function validationPatch(deviceId, customer) {
|
||||
return validateOfac(deviceId, customer).then(sanctions =>
|
||||
_.isNil(customer.sanctions) || customer.sanctions !== sanctions
|
||||
? { sanctions }
|
||||
: {},
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {validationPatch}
|
||||
module.exports = { validationPatch }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue