From c2329be5881243b8d5d36151bc88f1bd677a1dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Thu, 27 Jan 2022 15:38:48 +0000 Subject: [PATCH] fix: send manually entered customer data to machine --- lib/customers.js | 17 +++++++++-------- lib/routes/phoneCodeRoutes.js | 5 ++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/customers.js b/lib/customers.js index a9e57ef8..09e7d031 100644 --- a/lib/customers.js +++ b/lib/customers.js @@ -88,10 +88,7 @@ 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(assignCustomerData) .then(addComplianceOverrides(id, updateData, userToken)) .then(populateOverrideUsernames) .then(computeStatus) @@ -324,6 +321,7 @@ function getById (id, userToken) { .then(populateOverrideUsernames) .then(computeStatus) .then(populateDailyVolume) + .then(assignCustomerData) .then(getCustomInfoRequestsData) .then(camelize) } @@ -723,15 +721,18 @@ function getCustomerById (id) { WHERE c.id = $2 ) AS cl WHERE rn = 1` return db.oneOrNone(sql, [passableErrorCodes, id]) - .then(customerData => { - return getEditedData(id) - .then(customerEditedData => selectLatestData(customerData, customerEditedData)) - }) + .then(assignCustomerData) .then(populateOverrideUsernames) .then(camelize) .then(it => ({ ...it, notes: (it.notes ?? []).map(camelize) })) } +function assignCustomerData (customer) { + return getEditedData(customer.id) + .then(customerEditedData => selectLatestData(customer, customerEditedData)) + .then(_.assign(customer)) +} + /** * Query the specific customer manually edited data * diff --git a/lib/routes/phoneCodeRoutes.js b/lib/routes/phoneCodeRoutes.js index 585c1e9d..4a4905bc 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 { get, add, getEditedData, selectLatestData, getById, update } = require('../customers') +const { get, add, getById, update } = require('../customers') const httpError = require('../route-helpers').httpError const plugins = require('../plugins') const Tx = require('../tx') @@ -26,8 +26,7 @@ function addOrUpdateCustomer (req) { return add(req.body) }) - .then(customer => Promise.all([getEditedData(customer.id), getById(customer.id, null)])) - .then(([customerEditedData, customerOriginalData]) => selectLatestData(customerOriginalData, customerEditedData)) + .then(customer => getById(customer.id)) .then(customer => { // BACKWARDS_COMPATIBILITY 7.5 // machines before 7.5 expect customer with sanctions result