Merge pull request #1103 from chaotixkilla/fix-missing-custom-req-data-machine-response
Fix missing customer data on machine requests
This commit is contained in:
commit
b353f68236
8 changed files with 100 additions and 32 deletions
|
|
@ -520,7 +520,11 @@ function getCustomersList (phone = null, name = null, address = null, id = null)
|
|||
AND ($7 IS NULL OR id_card_data::json->>'documentNumber' = $7)
|
||||
limit $3`
|
||||
return db.any(sql, [ passableErrorCodes, anonymous.uuid, NUM_RESULTS, phone, name, address, id ])
|
||||
.then(customers => Promise.all(_.map(camelizeDeep, customers)))
|
||||
.then(customers => Promise.all(_.map(customer =>
|
||||
getCustomInfoRequestsData(customer)
|
||||
.then(camelizeDeep), customers)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -569,6 +573,7 @@ function getCustomerById (id) {
|
|||
) AS cl WHERE rn = 1`
|
||||
return db.oneOrNone(sql, [passableErrorCodes, id])
|
||||
.then(assignCustomerData)
|
||||
.then(getCustomInfoRequestsData)
|
||||
.then(camelizeDeep)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,13 +113,19 @@ const setCustomerData = (customerId, infoRequestId, data) => {
|
|||
INSERT INTO customers_custom_info_requests (customer_id, info_request_id, customer_data)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (customer_id, info_request_id)
|
||||
DO UPDATE SET customer_data = $3,
|
||||
override = 'automatic',
|
||||
override_by = NULL,
|
||||
override_at = NULL`
|
||||
DO UPDATE SET customer_data = $3`
|
||||
return db.none(sql, [customerId, infoRequestId, data])
|
||||
}
|
||||
|
||||
const setCustomerDataViaMachine = (customerId, infoRequestId, data) => {
|
||||
const sql = `
|
||||
INSERT INTO customers_custom_info_requests (customer_id, info_request_id, customer_data)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (customer_id, info_request_id)
|
||||
DO UPDATE SET customer_data = $3, override = $4, override_by = $5, override_at = now()`
|
||||
return db.none(sql, [customerId, infoRequestId, data, 'automatic', null])
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getCustomInfoRequests,
|
||||
addCustomInfoRequest,
|
||||
|
|
@ -131,5 +137,6 @@ module.exports = {
|
|||
getCustomInfoRequest,
|
||||
batchGetCustomInfoRequest,
|
||||
setAuthorizedCustomRequest,
|
||||
setCustomerData
|
||||
setCustomerData,
|
||||
setCustomerDataViaMachine
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ function updateCustomerCustomInfoRequest (customerId, patch, req, res) {
|
|||
.then(customer => respond(req, res, { customer }))
|
||||
}
|
||||
|
||||
return customInfoRequestQueries.setCustomerData(customerId, patch.infoRequestId, patch)
|
||||
return customInfoRequestQueries.setCustomerDataViaMachine(customerId, patch.infoRequestId, patch)
|
||||
.then(() => customers.getById(customerId))
|
||||
.then(customer => respond(req, res, { customer }))
|
||||
}
|
||||
|
|
|
|||
6
new-lamassu-admin/package-lock.json
generated
6
new-lamassu-admin/package-lock.json
generated
|
|
@ -27467,9 +27467,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"uuid": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.3.tgz",
|
||||
"integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg=="
|
||||
"version": "8.3.2",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
||||
},
|
||||
"v8-compile-cache": {
|
||||
"version": "2.2.0",
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@
|
|||
"react-virtualized": "^9.21.2",
|
||||
"sanctuary": "^2.0.1",
|
||||
"ua-parser-js": "^1.0.2",
|
||||
"uuid": "^7.0.2",
|
||||
"uuid": "^8.3.2",
|
||||
"yup": "0.32.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -57,6 +57,22 @@ const GET_CUSTOMERS = gql`
|
|||
sanctionsOverride
|
||||
daysSuspended
|
||||
isSuspended
|
||||
customInfoRequests {
|
||||
customerId
|
||||
infoRequestId
|
||||
override
|
||||
overrideAt
|
||||
overrideBy
|
||||
customerData
|
||||
customInfoRequest {
|
||||
id
|
||||
enabled
|
||||
customRequest
|
||||
}
|
||||
}
|
||||
}
|
||||
customInfoRequests {
|
||||
id
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
@ -110,6 +126,8 @@ const Customers = () => {
|
|||
})
|
||||
|
||||
const configData = R.path(['config'])(customersResponse) ?? []
|
||||
const customRequirementsData =
|
||||
R.path(['customInfoRequests'], customersResponse) ?? []
|
||||
const locale = configData && fromNamespace(namespaces.LOCALE, configData)
|
||||
const triggers = configData && fromNamespace(namespaces.TRIGGERS, configData)
|
||||
const customersData = R.sortWith([
|
||||
|
|
@ -207,6 +225,7 @@ const Customers = () => {
|
|||
onClick={handleCustomerClicked}
|
||||
loading={customerLoading}
|
||||
triggers={triggers}
|
||||
customRequests={customRequirementsData}
|
||||
/>
|
||||
<CreateCustomerModal
|
||||
showModal={showCreationModal}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,14 @@ import { getAuthorizedStatus, getFormattedPhone, getName } from './helper'
|
|||
|
||||
const useStyles = makeStyles(styles)
|
||||
|
||||
const CustomersList = ({ data, locale, onClick, loading, triggers }) => {
|
||||
const CustomersList = ({
|
||||
data,
|
||||
locale,
|
||||
onClick,
|
||||
loading,
|
||||
triggers,
|
||||
customRequests
|
||||
}) => {
|
||||
const classes = useStyles()
|
||||
|
||||
const elements = [
|
||||
|
|
@ -66,7 +73,11 @@ const CustomersList = ({ data, locale, onClick, loading, triggers }) => {
|
|||
{
|
||||
header: 'Status',
|
||||
width: 191,
|
||||
view: it => <MainStatus statuses={[getAuthorizedStatus(it, triggers)]} />
|
||||
view: it => (
|
||||
<MainStatus
|
||||
statuses={[getAuthorizedStatus(it, triggers, customRequests)]}
|
||||
/>
|
||||
)
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { parse, isValid, format } from 'date-fns/fp'
|
|||
import { Field, useFormikContext } from 'formik'
|
||||
import { parsePhoneNumberFromString } from 'libphonenumber-js'
|
||||
import * as R from 'ramda'
|
||||
import * as uuid from 'uuid'
|
||||
import * as Yup from 'yup'
|
||||
|
||||
import {
|
||||
|
|
@ -56,14 +57,11 @@ const CUSTOM = 'custom'
|
|||
const REQUIREMENT = 'requirement'
|
||||
const ID_CARD_DATA = 'idCardData'
|
||||
|
||||
const getAuthorizedStatus = (it, triggers) => {
|
||||
const fields = [
|
||||
'frontCamera',
|
||||
'idCardData',
|
||||
'idCardPhoto',
|
||||
'usSsn',
|
||||
'sanctions'
|
||||
]
|
||||
const getAuthorizedStatus = (it, triggers, customRequests) => {
|
||||
const fields = R.concat(
|
||||
['frontCamera', 'idCardData', 'idCardPhoto', 'usSsn', 'sanctions'],
|
||||
R.map(ite => ite.id, customRequests)
|
||||
)
|
||||
const fieldsWithPathSuffix = ['frontCamera', 'idCardPhoto']
|
||||
|
||||
const isManualField = fieldName => {
|
||||
|
|
@ -83,17 +81,43 @@ const getAuthorizedStatus = (it, triggers) => {
|
|||
)
|
||||
}
|
||||
|
||||
const pendingFieldStatus = R.map(
|
||||
ite =>
|
||||
!R.isNil(
|
||||
R.includes(ite, fieldsWithPathSuffix) ? it[`${ite}Path`] : it[`${ite}`]
|
||||
)
|
||||
? isManualField(ite)
|
||||
? R.equals(it[`${ite}Override`], 'automatic')
|
||||
: false
|
||||
: false,
|
||||
fields
|
||||
)
|
||||
const pendingFieldStatus = R.map(ite => {
|
||||
if (isManualField(ite)) {
|
||||
if (uuid.validate(ite)) {
|
||||
const request = R.find(
|
||||
iter => iter.infoRequestId === ite,
|
||||
it.customInfoRequests
|
||||
)
|
||||
return !R.isNil(request) && R.equals(request.override, 'automatic')
|
||||
}
|
||||
|
||||
const regularFieldValue = R.includes(ite, fieldsWithPathSuffix)
|
||||
? it[`${ite}Path`]
|
||||
: it[`${ite}`]
|
||||
if (R.isNil(regularFieldValue)) return false
|
||||
return R.equals(it[`${ite}Override`], 'automatic')
|
||||
}
|
||||
return false
|
||||
}, fields)
|
||||
|
||||
const rejectedFieldStatus = R.map(ite => {
|
||||
if (isManualField(ite)) {
|
||||
if (uuid.validate(ite)) {
|
||||
const request = R.find(
|
||||
iter => iter.infoRequestId === ite,
|
||||
it.customInfoRequests
|
||||
)
|
||||
return !R.isNil(request) && R.equals(request.override, 'blocked')
|
||||
}
|
||||
|
||||
const regularFieldValue = R.includes(ite, fieldsWithPathSuffix)
|
||||
? it[`${ite}Path`]
|
||||
: it[`${ite}`]
|
||||
if (R.isNil(regularFieldValue)) return false
|
||||
return R.equals(it[`${ite}Override`], 'blocked')
|
||||
}
|
||||
return false
|
||||
}, fields)
|
||||
|
||||
if (it.authorizedOverride === CUSTOMER_BLOCKED)
|
||||
return { label: 'Blocked', type: 'error' }
|
||||
|
|
@ -101,6 +125,8 @@ const getAuthorizedStatus = (it, triggers) => {
|
|||
return it.daysSuspended > 0
|
||||
? { label: `${it.daysSuspended} day suspension`, type: 'warning' }
|
||||
: { label: `< 1 day suspension`, type: 'warning' }
|
||||
if (R.any(ite => ite === true, rejectedFieldStatus))
|
||||
return { label: 'Rejected', type: 'error' }
|
||||
if (R.any(ite => ite === true, pendingFieldStatus))
|
||||
return { label: 'Pending', type: 'warning' }
|
||||
return { label: 'Authorized', type: 'success' }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue