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

@ -45,6 +45,7 @@ const getStatusMap = (settings, customerExternalCompliance) => {
_.uniq
)(triggers)
const meta = {}
const applicantPromises = _.map(service => {
return getStatus(settings, service, customerExternalCompliance)
})(services)
@ -81,7 +82,6 @@ const getApplicantByExternalId = (settings, externalService, customerId) => {
module.exports = {
getStatusMap,
getStatus,
createApplicant,
getApplicantByExternalId,
createLink

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])

View file

@ -40,7 +40,7 @@ const typeDef = gql`
customInfoRequests: [CustomRequestData]
notes: [CustomerNote]
isTestCustomer: Boolean
externalCompliance: JSONObject
externalCompliance: [JSONObject]
}
input CustomerInput {

View file

@ -39,7 +39,6 @@ const createLink = (account, userId, level) => {
}
const getApplicantByExternalId = (account, id) => {
console.log('id', id)
if (!id) {
return Promise.reject('Missing required fields: id')
}

View file

@ -31,18 +31,17 @@ const getApplicantStatus = (account, userId) => {
const reviewStatus = _.get('data.review.reviewStatus', r)
const reviewAnswer = _.get('data.review.reviewResult.reviewAnswer', r)
const reviewRejectType = _.get('data.review.reviewResult.reviewRejectType', r)
const sumsubUserId = _.get('data.review.reviewResult.reviewRejectType', r)
console.log('levelName', levelName)
console.log('reviewStatus', reviewStatus)
console.log('reviewAnswer', reviewAnswer)
console.log('reviewRejectType', reviewRejectType)
// if last review was from a different level, return the current level and RETRY
if (levelName !== account.applicantLevel) return { thirdPartyId: sumsubUserId, level: account.applicantLevel, answer: RETRY }
let answer = WAIT
if (reviewAnswer === 'GREEN') answer = APPROVED
if (reviewAnswer === 'GREEN' && reviewStatus === 'completed') answer = APPROVED
if (reviewAnswer === 'RED' && reviewRejectType === 'RETRY') answer = RETRY
if (reviewAnswer === 'RED' && reviewRejectType === 'FINAL') answer = REJECTED
return { level: levelName, answer }
return { thirdPartyId: sumsubUserId, level: levelName, answer }
})
}