Embed populateOverrideUsernames into format function

This commit is contained in:
goga-m 2017-09-29 21:10:04 +03:00 committed by Josh Harvey
parent 2abed2ed57
commit e907f8a70a

View file

@ -44,14 +44,12 @@ function update (id, data, userToken) {
' where id=$1 returning *' ' where id=$1 returning *'
return db.one(sql, [id]) return db.one(sql, [id])
.then(addComplianceOverrides(id, updateData, userToken)) .then(addComplianceOverrides(id, updateData, userToken))
.then(populateOverrideUsernames)
.then(format) .then(format)
} }
function getById (id, userToken) { function getById (id, userToken) {
const sql = 'select * from customers where id=$1' const sql = 'select * from customers where id=$1'
return db.oneOrNone(sql, [id]) return db.oneOrNone(sql, [id])
.then(populateOverrideUsernames)
.then(format) .then(format)
} }
@ -171,13 +169,13 @@ function format (customer) {
value: customer.id_card_image_at value: customer.id_card_image_at
}]) }])
customer.status = status.label customer.status = status.label
return camelize(customer) return populateOverrideUsernames(customer)
.then(camelize)
} }
/** /**
* Populate the customer object with user names * Populate the customer object with user names
* only for those override fields that contain * for override fields
* *override_by values (user token references)
* *
* @name populateOverrideUsernames * @name populateOverrideUsernames
* @function * @function
@ -211,7 +209,7 @@ function batch () {
where id != $1 where id != $1
order by created desc limit $2` order by created desc limit $2`
return db.any(sql, [ anonymous.uuid, NUM_RESULTS ]) 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 } module.exports = { add, get, batch, getById, update }