refactor: yagni and flow of external compliance

This commit is contained in:
Rafael Taranto 2024-06-17 22:11:24 +01:00
parent b06927fd1c
commit 04eea85a0d
29 changed files with 389 additions and 1417 deletions

View file

@ -932,13 +932,30 @@ function updateLastAuthAttempt (customerId) {
function getExternalCustomerData (customer) {
return settingsLoader.loadLatest()
.then(settings => externalCompliance.getApplicant(settings, customer))
.then(externalCompliance => {
customer.externalCompliance = externalCompliance
return customer
.then(settings => externalCompliance.getStatusMap(settings, customer.id))
.then(statusMap => {
return updateExternalCompliance(customer.id, statusMap)
.then(() => customer.externalCompliance = statusMap)
.then(() => customer)
})
}
function updateExternalCompliance(customerId, serviceMap) {
const sql = `
UPDATE customer_external_compliance SET last_known_status = $1, last_updated = now()
WHERE customer_id=$2 AND service=$3
`
const pairs = _.toPairs(serviceMap)
const promises = _.map(([service, status]) => db.none(sql, [status.answer, customerId, service]))(pairs)
return Promise.all(promises)
}
function addExternalCompliance(customerId, service, id) {
const sql = `INSERT INTO customer_external_compliance (customer_id, external_id, service) VALUES ($1, $2, $3)`
return db.none(sql, [customerId, id, service])
}
module.exports = {
add,
addWithEmail,
@ -962,5 +979,6 @@ module.exports = {
updateTxCustomerPhoto,
enableTestCustomer,
disableTestCustomer,
updateLastAuthAttempt
updateLastAuthAttempt,
addExternalCompliance
}