diff --git a/lib/customers.js b/lib/customers.js index cf6f30fb..1f15dc91 100644 --- a/lib/customers.js +++ b/lib/customers.js @@ -88,6 +88,10 @@ function update (id, data, userToken, txId) { ' where id=$1 returning *' return db.one(sql, [id]) + .then(customerData => { + return getEditedData(id) + .then(customerEditedData => selectLatestData(customerData, customerEditedData)) + }) .then(addComplianceOverrides(id, updateData, userToken)) .then(populateOverrideUsernames) .then(computeStatus) @@ -1053,5 +1057,7 @@ module.exports = { updateEditedPhoto, updateTxCustomerPhoto, enableTestCustomer, - disableTestCustomer + disableTestCustomer, + selectLatestData, + getEditedData } diff --git a/lib/routes/phoneCodeRoutes.js b/lib/routes/phoneCodeRoutes.js index bd03c3c9..ac92531f 100644 --- a/lib/routes/phoneCodeRoutes.js +++ b/lib/routes/phoneCodeRoutes.js @@ -6,7 +6,7 @@ const _ = require('lodash/fp') const compliance = require('../compliance') const complianceTriggers = require('../compliance-triggers') 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 plugins = require('../plugins') const Tx = require('../tx') @@ -20,12 +20,14 @@ function addOrUpdateCustomer (req) { const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers) const maxDaysThreshold = complianceTriggers.maxDaysThreshold(triggers) - return customers.get(customerData.phone) + return get(customerData.phone) .then(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 => { // BACKWARDS_COMPATIBILITY 7.5 // machines before 7.5 expect customer with sanctions result @@ -36,7 +38,7 @@ function addOrUpdateCustomer (req) { return compliance.validationPatch(req.deviceId, !!compatTriggers.sanctions, customer) .then(patch => { if (_.isEmpty(patch)) return customer - return customers.update(customer.id, patch) + return update(customer.id, patch) }) }) .then(customer => {