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 *'
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 }