fix: improve individual discount loading
This commit is contained in:
parent
3ccc202efa
commit
ac56ace4bd
5 changed files with 44 additions and 19 deletions
|
|
@ -487,6 +487,14 @@ function batch () {
|
|||
}, customers)))
|
||||
}
|
||||
|
||||
function getSlimCustomerByIdBatch (ids) {
|
||||
const sql = `SELECT id, phone, id_card_data
|
||||
FROM customers
|
||||
WHERE id = ANY($1::uuid[])`
|
||||
return db.any(sql, [ids])
|
||||
.then(customers => _.map(camelize, customers))
|
||||
}
|
||||
|
||||
// TODO: getCustomersList and getCustomerById are very similar, so this should be refactored
|
||||
|
||||
/**
|
||||
|
|
@ -612,18 +620,18 @@ function formatSubscriberInfo(customer) {
|
|||
if(!subscriberInfo) return customer
|
||||
const result = subscriberInfo.result
|
||||
if(_.isEmpty(result)) return _.omit(['subscriberInfo'], customer)
|
||||
|
||||
|
||||
const name = _.get('belongs_to.name')(result)
|
||||
const street = _.get('current_addresses[0].street_line_1')(result)
|
||||
const city = _.get('current_addresses[0].city')(result)
|
||||
const stateCode = _.get('current_addresses[0].state_code')(result)
|
||||
const postalCode = _.get('current_addresses[0].postal_code')(result)
|
||||
|
||||
customer.subscriberInfo = {
|
||||
name,
|
||||
|
||||
customer.subscriberInfo = {
|
||||
name,
|
||||
address: `${street ?? ''} ${city ?? ''}${street || city ? ',' : ''} ${stateCode ?? ''} ${postalCode ?? ''}`
|
||||
}
|
||||
|
||||
|
||||
return customer
|
||||
}
|
||||
|
||||
|
|
@ -1032,6 +1040,7 @@ module.exports = {
|
|||
get,
|
||||
getWithEmail,
|
||||
batch,
|
||||
getSlimCustomerByIdBatch,
|
||||
getCustomersList,
|
||||
getCustomerById,
|
||||
getById,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue