From 724e8c05b1064f3ea456bc74b9a89878dace45d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Fri, 11 Feb 2022 15:42:12 +0000 Subject: [PATCH] fix: `.then()` on non-Promise --- lib/customers.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/customers.js b/lib/customers.js index d60f6a3c..2a0da442 100644 --- a/lib/customers.js +++ b/lib/customers.js @@ -330,6 +330,13 @@ function camelize (customer) { return customer ? _.mapKeys(_.camelCase, customer) : null } +function camelizeDeep (customer) { + return _.flow( + camelize, + it => ({ ...it, notes: (it.notes ?? []).map(camelize) }) + )(customer) +} + /** * Get all available complianceTypes * that can be overriden (excluding hard_limit) @@ -513,10 +520,7 @@ function getCustomersList (phone = null, name = null, address = null, id = null) AND ($7 IS NULL OR id_card_data::json->>'documentNumber' = $7) limit $3` return db.any(sql, [ passableErrorCodes, anonymous.uuid, NUM_RESULTS, phone, name, address, id ]) - .then(customers => Promise.all(_.map(customer => { - return camelize(customer) - .then(it => ({ ...it, notes: (it.notes ?? []).map(camelize) })) - }, customers))) + .then(customers => Promise.all(_.map(camelizeDeep, customers))) } /** @@ -565,8 +569,7 @@ function getCustomerById (id) { ) AS cl WHERE rn = 1` return db.oneOrNone(sql, [passableErrorCodes, id]) .then(assignCustomerData) - .then(camelize) - .then(it => ({ ...it, notes: (it.notes ?? []).map(camelize) })) + .then(camelizeDeep) } function assignCustomerData (customer) {