fix: improve individual discount loading

This commit is contained in:
Rafael Taranto 2025-04-17 09:48:56 +01:00
parent 3ccc202efa
commit ac56ace4bd
5 changed files with 44 additions and 19 deletions

View file

@ -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,