fix: latest customer data selection and button margin

This commit is contained in:
José Oliveira 2021-11-10 19:02:46 +00:00
parent 68c635ce38
commit b77b732bcb
5 changed files with 58 additions and 34 deletions

View file

@ -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
}

View file

@ -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)
}
}
}

View file

@ -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() )`
]

View file

@ -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
}
}

View file

@ -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,