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

View file

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

View file

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

View file

@ -39,7 +39,6 @@ const createLink = (account, userId, level) => {
} }
const getApplicantByExternalId = (account, id) => { const getApplicantByExternalId = (account, id) => {
console.log('id', id)
if (!id) { if (!id) {
return Promise.reject('Missing required fields: 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 reviewStatus = _.get('data.review.reviewStatus', r)
const reviewAnswer = _.get('data.review.reviewResult.reviewAnswer', r) const reviewAnswer = _.get('data.review.reviewResult.reviewAnswer', r)
const reviewRejectType = _.get('data.review.reviewResult.reviewRejectType', r) const reviewRejectType = _.get('data.review.reviewResult.reviewRejectType', r)
const sumsubUserId = _.get('data.review.reviewResult.reviewRejectType', r)
console.log('levelName', levelName) // if last review was from a different level, return the current level and RETRY
console.log('reviewStatus', reviewStatus) if (levelName !== account.applicantLevel) return { thirdPartyId: sumsubUserId, level: account.applicantLevel, answer: RETRY }
console.log('reviewAnswer', reviewAnswer)
console.log('reviewRejectType', reviewRejectType)
let answer = WAIT 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 === 'RETRY') answer = RETRY
if (reviewAnswer === 'RED' && reviewRejectType === 'FINAL') answer = REJECTED if (reviewAnswer === 'RED' && reviewRejectType === 'FINAL') answer = REJECTED
return { level: levelName, answer } return { thirdPartyId: sumsubUserId, level: levelName, answer }
}) })
} }

View file

@ -400,22 +400,34 @@ const CustomerData = ({
}) })
}, R.keys(smsData) ?? []) }, R.keys(smsData) ?? [])
// TODO - add external compliance data R.forEach(it => {
// R.forEach(outer => { externalCompliance.push({
// initialValues. fields: [
// externalCompliance.push({ {
// fields: [ name: 'externalId',
// { label: 'Third Party ID',
// name: 'lastKnownStatus', editable: false
// label: 'Last Known Status', },
// component: TextInput {
// } name: 'lastKnownStatus',
// ], label: 'Last Known Status',
// titleIcon: <CardIcon className={classes.cardIcon} />, editable: false
// state: outer.state, },
// title: 'External Info' {
// }) name: 'lastUpdated',
// })(R.keys(customer.externalCompliance)) label: 'Last Updated',
editable: false
}
],
titleIcon: <CardIcon className={classes.cardIcon} />,
title: `External Info [${it.service}]`,
initialValues: it ?? {
externalId: '',
lastKnownStatus: '',
lastUpdated: ''
}
})
})(customer.externalCompliance ?? [])
const editableCard = ( const editableCard = (
{ {
@ -459,7 +471,7 @@ const CustomerData = ({
} }
const nonEditableCard = ( const nonEditableCard = (
{ title, state, titleIcon, fields, hasImage }, { title, state, titleIcon, fields, hasImage, initialValues, children },
idx idx
) => { ) => {
return ( return (
@ -467,6 +479,8 @@ const CustomerData = ({
title={title} title={title}
key={idx} key={idx}
state={state} state={state}
children={children}
initialValues={initialValues}
titleIcon={titleIcon} titleIcon={titleIcon}
editable={false} editable={false}
hasImage={hasImage} hasImage={hasImage}