From e907f8a70a215574d161640cc6d2299dab3f8645 Mon Sep 17 00:00:00 2001 From: goga-m Date: Fri, 29 Sep 2017 21:10:04 +0300 Subject: [PATCH] Embed populateOverrideUsernames into format function --- lib/customers.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/customers.js b/lib/customers.js index f971b363..7ae8ce10 100644 --- a/lib/customers.js +++ b/lib/customers.js @@ -44,14 +44,12 @@ function update (id, data, userToken) { ' where id=$1 returning *' return db.one(sql, [id]) .then(addComplianceOverrides(id, updateData, userToken)) - .then(populateOverrideUsernames) .then(format) } function getById (id, userToken) { const sql = 'select * from customers where id=$1' return db.oneOrNone(sql, [id]) - .then(populateOverrideUsernames) .then(format) } @@ -171,13 +169,13 @@ function format (customer) { value: customer.id_card_image_at }]) customer.status = status.label - return camelize(customer) + return populateOverrideUsernames(customer) + .then(camelize) } /** * Populate the customer object with user names - * only for those override fields that contain - * *override_by values (user token references) + * for override fields * * @name populateOverrideUsernames * @function @@ -211,7 +209,7 @@ function batch () { where id != $1 order by created desc limit $2` return db.any(sql, [ anonymous.uuid, NUM_RESULTS ]) - .then(_.map(format)) + .then(customers => Promise.all(_.map(format, customers))) } module.exports = { add, get, batch, getById, update }