fix: admin ui

This commit is contained in:
Rafael Taranto 2024-06-18 10:42:59 +01:00
parent 04eea85a0d
commit 11e0a03df1
6 changed files with 57 additions and 30 deletions

View file

@ -323,7 +323,7 @@ function getById (id) {
return db.oneOrNone(sql, [id])
.then(assignCustomerData)
.then(getCustomInfoRequestsData)
.then(getExternalCustomerData)
.then(getExternalComplianceMachine)
.then(camelize)
}
@ -344,7 +344,11 @@ function camelize (customer) {
function camelizeDeep (customer) {
return _.flow(
camelize,
it => ({ ...it, notes: (it.notes ?? []).map(camelize) })
it => ({
...it,
notes: (it.notes ?? []).map(camelize),
externalCompliance: (it.externalCompliance ?? []).map(camelize)
})
)(customer)
}
@ -589,9 +593,9 @@ function getCustomerById (id) {
return db.oneOrNone(sql, [passableErrorCodes, id])
.then(assignCustomerData)
.then(getCustomInfoRequestsData)
.then(getExternalCompliance)
.then(camelizeDeep)
.then(formatSubscriberInfo)
.then(getExternalCustomerData)
}
function assignCustomerData (customer) {
@ -930,7 +934,7 @@ function updateLastAuthAttempt (customerId) {
return db.none(sql, [customerId])
}
function getExternalCustomerData (customer) {
function getExternalComplianceMachine (customer) {
return settingsLoader.loadLatest()
.then(settings => externalCompliance.getStatusMap(settings, customer.id))
.then(statusMap => {
@ -950,6 +954,17 @@ function updateExternalCompliance(customerId, serviceMap) {
return Promise.all(promises)
}
function getExternalCompliance(customer) {
const sql = `SELECT external_id, service, last_known_status, last_updated
FROM customer_external_compliance where customer_id=$1`
return db.manyOrNone(sql, [customer.id])
.then(compliance => {
console.log(compliance)
customer.externalCompliance = compliance
})
.then(() => customer)
}
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])