fix: format twilio api response

This commit is contained in:
José Oliveira 2022-02-22 15:17:46 +00:00
parent 3c33695b9d
commit 229c77eca2
2 changed files with 23 additions and 2 deletions

View file

@ -575,6 +575,7 @@ function getCustomerById (id) {
.then(assignCustomerData) .then(assignCustomerData)
.then(getCustomInfoRequestsData) .then(getCustomInfoRequestsData)
.then(camelizeDeep) .then(camelizeDeep)
.then(formatSubscriberInfo)
} }
function assignCustomerData (customer) { function assignCustomerData (customer) {
@ -582,6 +583,26 @@ function assignCustomerData (customer) {
.then(customerEditedData => selectLatestData(customer, customerEditedData)) .then(customerEditedData => selectLatestData(customer, customerEditedData))
} }
function formatSubscriberInfo(customer) {
const subscriberInfo = customer.subscriberInfo
if(!subscriberInfo) return customer
const result = subscriberInfo.result
if(subscriberInfo.status !== 'successful' || _.isEmpty(result)) return 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,
address: `${street ?? ''} ${city ?? ''}${street || city ? ',' : ''} ${stateCode ?? ''} ${postalCode ?? ''}`
}
return customer
}
/** /**
* Query the specific customer manually edited data * Query the specific customer manually edited data
* *

View file

@ -103,7 +103,7 @@ const CustomerData = ({
) )
const phone = R.path(['phone'])(customer) const phone = R.path(['phone'])(customer)
const smsData = R.path(['subscriberInfo', 'result'])(customer) const smsData = R.path(['subscriberInfo'])(customer)
const isEven = elem => elem % 2 === 0 const isEven = elem => elem % 2 === 0
@ -373,7 +373,7 @@ const CustomerData = ({
name: it, name: it,
label: onlyFirstToUpper(it), label: onlyFirstToUpper(it),
component: TextInput, component: TextInput,
editable: true editable: false
}) })
}, R.keys(smsData) ?? []) }, R.keys(smsData) ?? [])