From 81d74eb40b0ecffa6e94b174853986ea65f25c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Thu, 10 Feb 2022 20:28:20 +0000 Subject: [PATCH 1/4] fix: add missing custom requirement data on customer data communication with machine fix: create function to reset the override flag in custom requirement data --- lib/customers.js | 7 ++++++- lib/new-admin/services/customInfoRequests.js | 12 +++++++++++- lib/routes/customerRoutes.js | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/customers.js b/lib/customers.js index 2a0da442..ae7d436f 100644 --- a/lib/customers.js +++ b/lib/customers.js @@ -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) } diff --git a/lib/new-admin/services/customInfoRequests.js b/lib/new-admin/services/customInfoRequests.js index 14d402dd..a8579bef 100644 --- a/lib/new-admin/services/customInfoRequests.js +++ b/lib/new-admin/services/customInfoRequests.js @@ -120,6 +120,15 @@ const setCustomerData = (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 = { getCustomInfoRequests, addCustomInfoRequest, @@ -131,5 +140,6 @@ module.exports = { getCustomInfoRequest, batchGetCustomInfoRequest, setAuthorizedCustomRequest, - setCustomerData + setCustomerData, + setCustomerDataViaMachine } diff --git a/lib/routes/customerRoutes.js b/lib/routes/customerRoutes.js index e59acb52..08949aa9 100644 --- a/lib/routes/customerRoutes.js +++ b/lib/routes/customerRoutes.js @@ -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 })) } From 2a3e95448420591ccf67a55a247ae41a36d07208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Thu, 10 Feb 2022 21:39:00 +0000 Subject: [PATCH 2/4] chore: bump uuid version on UI side fix: add custom info requests to customer list status check --- new-lamassu-admin/package-lock.json | 6 +-- new-lamassu-admin/package.json | 2 +- .../src/pages/Customers/Customers.js | 19 ++++++++ .../src/pages/Customers/CustomersList.js | 15 ++++++- .../src/pages/Customers/helper.js | 43 +++++++++++-------- 5 files changed, 60 insertions(+), 25 deletions(-) diff --git a/new-lamassu-admin/package-lock.json b/new-lamassu-admin/package-lock.json index b54297ef..99d52c11 100644 --- a/new-lamassu-admin/package-lock.json +++ b/new-lamassu-admin/package-lock.json @@ -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", diff --git a/new-lamassu-admin/package.json b/new-lamassu-admin/package.json index ab5f4f1c..aa4c0382 100644 --- a/new-lamassu-admin/package.json +++ b/new-lamassu-admin/package.json @@ -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": { diff --git a/new-lamassu-admin/src/pages/Customers/Customers.js b/new-lamassu-admin/src/pages/Customers/Customers.js index 16cefc5d..a5bed041 100644 --- a/new-lamassu-admin/src/pages/Customers/Customers.js +++ b/new-lamassu-admin/src/pages/Customers/Customers.js @@ -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} /> { +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 => + view: it => ( + + ) } ] diff --git a/new-lamassu-admin/src/pages/Customers/helper.js b/new-lamassu-admin/src/pages/Customers/helper.js index cba19de8..e39265ae 100644 --- a/new-lamassu-admin/src/pages/Customers/helper.js +++ b/new-lamassu-admin/src/pages/Customers/helper.js @@ -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,24 @@ 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) if (it.authorizedOverride === CUSTOMER_BLOCKED) return { label: 'Blocked', type: 'error' } From 4ec4ec4917a04cdea368278d27d9c20ed2adcb5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Fri, 11 Feb 2022 16:00:36 +0000 Subject: [PATCH 3/4] feat: add rejected status to the customers list --- .../src/pages/Customers/helper.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/new-lamassu-admin/src/pages/Customers/helper.js b/new-lamassu-admin/src/pages/Customers/helper.js index e39265ae..e5338861 100644 --- a/new-lamassu-admin/src/pages/Customers/helper.js +++ b/new-lamassu-admin/src/pages/Customers/helper.js @@ -100,12 +100,33 @@ const getAuthorizedStatus = (it, triggers, customRequests) => { 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' } if (it.isSuspended) 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' } From 639dbe8eb129c73e575d6fe37e178c2bdd7e1546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Mon, 14 Feb 2022 15:28:38 +0000 Subject: [PATCH 4/4] fix: remove override reset on customer data saving via admin --- lib/new-admin/services/customInfoRequests.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/new-admin/services/customInfoRequests.js b/lib/new-admin/services/customInfoRequests.js index a8579bef..fff8dc39 100644 --- a/lib/new-admin/services/customInfoRequests.js +++ b/lib/new-admin/services/customInfoRequests.js @@ -113,10 +113,7 @@ 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]) }