From b77b732bcba9e779cdf8a82a4715c90ed222c888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 10 Nov 2021 19:02:46 +0000 Subject: [PATCH] fix: latest customer data selection and button margin --- lib/customers.js | 55 +++++++++++++------ .../graphql/resolvers/customer.resolver.js | 4 +- .../1635159374499-editable-customer-data.js | 24 ++++---- .../src/pages/Customers/CustomerProfile.js | 4 +- .../components/EditableCard.styles.js | 5 +- 5 files changed, 58 insertions(+), 34 deletions(-) diff --git a/lib/customers.js b/lib/customers.js index c839b97f..01cf7807 100644 --- a/lib/customers.js +++ b/lib/customers.js @@ -156,7 +156,7 @@ function edit (id, data, userToken) { 'id_card_data', 'id_card_photo', 'us_ssn', - 'subcriber_info', + 'subscriber_info', 'name' ] const filteredData = _.pick(defaults, _.mapKeys(_.snakeCase, _.omitBy(_.isNil, data))) @@ -192,8 +192,8 @@ function edit (id, data, userToken) { function enhanceEditedFields (fields, userToken) { if (!userToken) return fields _.mapKeys((field) => { - fields[field + '_edited_by'] = userToken - fields[field + '_edited_at'] = 'now()^' + fields[field + '_by'] = userToken + fields[field + '_at'] = 'now()^' }, fields) return fields } @@ -232,21 +232,21 @@ function enhanceEditedPhotos (fields) { function deleteEditedData (id, data) { // NOT IMPLEMENTING THIS FEATURE FOR THE CURRENT VERSION - // const defaults = [ - // 'front_camera', - // 'id_card_data', - // 'id_card_photo', - // 'us_ssn', - // 'subcriber_info', - // 'name' - // ] - // const filteredData = _.pick(defaults, _.mapKeys(_.snakeCase, data)) - // if (_.isEmpty(filteredData)) return getCustomerById(id) + const defaults = [ + 'front_camera', + 'id_card_data', + 'id_card_photo', + 'us_ssn', + 'subcriber_info', + 'name' + ] + const filteredData = _.pick(defaults, _.mapKeys(_.snakeCase, data)) + if (_.isEmpty(filteredData)) return getCustomerById(id) - // const cs = new Pgp.helpers.ColumnSet(_.keys(filteredData), - // { table: 'edited_customer_data' }) - // const update = Pgp.helpers.update(filteredData, cs) - // db.none(update) + const cs = new Pgp.helpers.ColumnSet(_.keys(filteredData), + { table: 'edited_customer_data' }) + const update = Pgp.helpers.update(filteredData, cs) + db.none(update) return getCustomerById(id) } @@ -726,6 +726,27 @@ function getEditedData (id) { } function selectLatestData (customerData, customerEditedData) { + const defaults = [ + 'front_camera', + 'id_card_data', + 'id_card_photo', + 'us_ssn', + 'subscriber_info', + 'name' + ] + _.map(field => { + let fieldName = field + if (_.includes(field, ['front_camera', 'id_card_photo'])) fieldName = fieldName + '_path' + const atField = field + '_at' + const byField = field + '_by' + if (!_.has(fieldName, customerData) || !_.has(fieldName, customerEditedData)) return + if (customerData[atField] < customerEditedData[atField]) { + customerData[fieldName] = customerEditedData[fieldName] + customerData[atField] = customerEditedData[atField] + customerData[byField] = customerEditedData[byField] + } + } + , defaults) return customerData } diff --git a/lib/new-admin/graphql/resolvers/customer.resolver.js b/lib/new-admin/graphql/resolvers/customer.resolver.js index 2db8b153..9ebf636f 100644 --- a/lib/new-admin/graphql/resolvers/customer.resolver.js +++ b/lib/new-admin/graphql/resolvers/customer.resolver.js @@ -29,11 +29,13 @@ const resolvers = { replacePhoto: async (root, { customerId, photoType, newPhoto }, context) => { const token = !!context.req.cookies.lid && context.req.session.user.id const photo = await newPhoto + if (!photo) return customers.getCustomerById(customerId) return customers.updateEditedPhoto(customerId, photo, photoType) .then(newPatch => customers.edit(customerId, newPatch, token)) }, deleteEditedData: (root, { customerId, customerEdit }) => { - return customers.deleteEditedData(customerId, customerEdit) + // NOT IMPLEMENTING THIS FEATURE FOR THE CURRENT VERSION + return customers.getCustomerById(customerId) } } } diff --git a/migrations/1635159374499-editable-customer-data.js b/migrations/1635159374499-editable-customer-data.js index 3da59080..c77ba5e8 100644 --- a/migrations/1635159374499-editable-customer-data.js +++ b/migrations/1635159374499-editable-customer-data.js @@ -5,23 +5,23 @@ exports.up = function (next) { `CREATE TABLE edited_customer_data ( customer_id uuid PRIMARY KEY REFERENCES customers(id), id_card_data JSON, - id_card_data_edited_at TIMESTAMPTZ, - id_card_data_edited_by UUID REFERENCES users(id), + id_card_data_at TIMESTAMPTZ, + id_card_data_by UUID REFERENCES users(id), front_camera_path TEXT, - front_camera_edited_at TIMESTAMPTZ, - front_camera_edited_by UUID REFERENCES users(id), + front_camera_at TIMESTAMPTZ, + front_camera_by UUID REFERENCES users(id), id_card_photo_path TEXT, - id_card_photo_edited_at TIMESTAMPTZ, - id_card_photo_edited_by UUID REFERENCES users(id), + id_card_photo_at TIMESTAMPTZ, + id_card_photo_by UUID REFERENCES users(id), subscriber_info JSON, - subscriber_info_edited_at TIMESTAMPTZ, - subscriber_info_edited_by UUID REFERENCES users(id), + subscriber_info_at TIMESTAMPTZ, + subscriber_info_by UUID REFERENCES users(id), name TEXT, - name_edited_at TIMESTAMPTZ, - name_edited_by UUID REFERENCES users(id), + name_at TIMESTAMPTZ, + name_by UUID REFERENCES users(id), us_ssn TEXT, - us_ssn_edited_at TIMESTAMPTZ, - us_ssn_edited_by UUID REFERENCES users(id), + us_ssn_at TIMESTAMPTZ, + us_ssn_by UUID REFERENCES users(id), created TIMESTAMPTZ NOT NULL DEFAULT now() )` ] diff --git a/new-lamassu-admin/src/pages/Customers/CustomerProfile.js b/new-lamassu-admin/src/pages/Customers/CustomerProfile.js index e8f980cd..41dc2dea 100644 --- a/new-lamassu-admin/src/pages/Customers/CustomerProfile.js +++ b/new-lamassu-admin/src/pages/Customers/CustomerProfile.js @@ -148,9 +148,9 @@ const DELETE_EDITED_CUSTOMER = gql` mutation deleteEditedData($customerId: ID!, $customerEdit: CustomerEdit) { deleteEditedData(customerId: $customerId, customerEdit: $customerEdit) { id - frontCamera + frontCameraPath idCardData - idCardPhoto + idCardPhotoPath usSsn } } diff --git a/new-lamassu-admin/src/pages/Customers/components/EditableCard.styles.js b/new-lamassu-admin/src/pages/Customers/components/EditableCard.styles.js index f97fea44..db50b8ae 100644 --- a/new-lamassu-admin/src/pages/Customers/components/EditableCard.styles.js +++ b/new-lamassu-admin/src/pages/Customers/components/EditableCard.styles.js @@ -29,13 +29,14 @@ export default { justifyContent: 'space-between' }, replace: { - marginTop: 30 + marginTop: 30, + marginRight: 5 }, input: { display: 'none' }, button: { - marginRight: 8 + marginRight: 5 }, editingButtons: { marginTop: 30,