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

@ -10,7 +10,7 @@ const OFAC_DATA_DIR = process.env.OFAC_DATA_DIR
let structs = null
function load () {
function load() {
if (!OFAC_DATA_DIR) {
const message = 'The ofacDataDir option has not been set in the environment'
return Promise.reject(new Error(message))
@ -19,10 +19,12 @@ function load () {
const ofacSourcesDir = path.join(OFAC_DATA_DIR, 'sources')
return readdir(ofacSourcesDir)
.then(_.flow(
_.map(file => path.join(ofacSourcesDir, file)),
loader.load
))
.then(
_.flow(
_.map(file => path.join(ofacSourcesDir, file)),
loader.load,
),
)
.then(result => {
return (structs = result)
})
@ -30,14 +32,14 @@ function load () {
// nameParts should be an object like {firstName: "John", lastName: "Doe", ...}
function makeCompatible (nameParts) {
function makeCompatible(nameParts) {
const partNames = _.keys(nameParts)
const values = _.map(_.lowerCase, _.values(nameParts))
const props = _.zipAll([partNames, values])
return _.map(_.zipObject(['partName', 'value']), props)
}
function match (nameParts, birthDateString, options) {
function match(nameParts, birthDateString, options) {
if (!structs) {
logger.error(new Error('The OFAC data sources have not been loaded yet.'))
return false
@ -50,24 +52,27 @@ function match (nameParts, birthDateString, options) {
// birthDateString is in YYYYMMDD format
const birthDate = _.cond([
[_.identity, () => {
const year = parseInt(birthDateString.slice(0, 4))
const month = parseInt(birthDateString.slice(4, 6))
const day = parseInt(birthDateString.slice(6, 8))
const date = new Date(year, month - 1, day)
[
_.identity,
() => {
const year = parseInt(birthDateString.slice(0, 4))
const month = parseInt(birthDateString.slice(4, 6))
const day = parseInt(birthDateString.slice(6, 8))
const date = new Date(year, month - 1, day)
return {year, month, day, date}
}],
[_.stubTrue, () => null]
return { year, month, day, date }
},
],
[_.stubTrue, () => null],
])(birthDateString)
const candidate = {parts, fullName, words, birthDate}
const candidate = { parts, fullName, words, birthDate }
const result = matcher.match(structs, candidate, options)
return result
}
function getStructs () {
function getStructs() {
return structs
}
module.exports = {load, match, getStructs}
module.exports = { load, match, getStructs }