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