Merge pull request #1058 from josepfo/fix/manually-entered-data-not-propagated-to-machine

fix: add manual data to customer info
This commit is contained in:
Rafael Taranto 2022-01-20 20:21:53 +00:00 committed by GitHub
commit c072803ac3
2 changed files with 13 additions and 5 deletions

View file

@ -88,6 +88,10 @@ function update (id, data, userToken, txId) {
' where id=$1 returning *' ' where id=$1 returning *'
return db.one(sql, [id]) return db.one(sql, [id])
.then(customerData => {
return getEditedData(id)
.then(customerEditedData => selectLatestData(customerData, customerEditedData))
})
.then(addComplianceOverrides(id, updateData, userToken)) .then(addComplianceOverrides(id, updateData, userToken))
.then(populateOverrideUsernames) .then(populateOverrideUsernames)
.then(computeStatus) .then(computeStatus)
@ -1053,5 +1057,7 @@ module.exports = {
updateEditedPhoto, updateEditedPhoto,
updateTxCustomerPhoto, updateTxCustomerPhoto,
enableTestCustomer, enableTestCustomer,
disableTestCustomer disableTestCustomer,
selectLatestData,
getEditedData
} }

View file

@ -6,7 +6,7 @@ const _ = require('lodash/fp')
const compliance = require('../compliance') const compliance = require('../compliance')
const complianceTriggers = require('../compliance-triggers') const complianceTriggers = require('../compliance-triggers')
const configManager = require('../new-config-manager') const configManager = require('../new-config-manager')
const customers = require('../customers') const { get, add, getEditedData, selectLatestData, getCustomerById, update } = require('../customers')
const httpError = require('../route-helpers').httpError const httpError = require('../route-helpers').httpError
const plugins = require('../plugins') const plugins = require('../plugins')
const Tx = require('../tx') const Tx = require('../tx')
@ -20,12 +20,14 @@ function addOrUpdateCustomer (req) {
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers) const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
const maxDaysThreshold = complianceTriggers.maxDaysThreshold(triggers) const maxDaysThreshold = complianceTriggers.maxDaysThreshold(triggers)
return customers.get(customerData.phone) return get(customerData.phone)
.then(customer => { .then(customer => {
if (customer) return customer if (customer) return customer
return customers.add(req.body) return add(req.body)
}) })
.then(customer => Promise.all([getEditedData(customer.id), getCustomerById(customer.id)]))
.then(([customerEditedData, customerOriginalData]) => selectLatestData(customerOriginalData, customerEditedData))
.then(customer => { .then(customer => {
// BACKWARDS_COMPATIBILITY 7.5 // BACKWARDS_COMPATIBILITY 7.5
// machines before 7.5 expect customer with sanctions result // machines before 7.5 expect customer with sanctions result
@ -36,7 +38,7 @@ function addOrUpdateCustomer (req) {
return compliance.validationPatch(req.deviceId, !!compatTriggers.sanctions, customer) return compliance.validationPatch(req.deviceId, !!compatTriggers.sanctions, customer)
.then(patch => { .then(patch => {
if (_.isEmpty(patch)) return customer if (_.isEmpty(patch)) return customer
return customers.update(customer.id, patch) return update(customer.id, patch)
}) })
}) })
.then(customer => { .then(customer => {