Currently, I am working on a small project using VueJS 2.0
, and it involves handling data that looks like this:
{"data":
[
{
"id":8,
"salutation":"Mr",
"first_name":"Madhu",
"last_name":"Kela",
"number":"2343253455",
"mobile":"3252345435",
"email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82efe3e6eaf7c2f0e7eeebe3ece1e7efe4ace1edef">[email protected]</a>",
"alt_email":null,
"address":"Mumbai BKC",
"city":"Mumbai",
"state":null,
"country":"India",
"profile":null,
"sectors_interested":"[\"Insurance\",\"Infrastructure\",\"Information Technology\",\"hevy machines\",\"Healtcare\"]",
"companies_interested":"[4]",
"interactions_count":11,
"client_interactions_count":0,
"company":[
{
"id":7,
"name":"Reliance MF",
"address":"Mumbai BKC",
"city":"Mumbai",
"state":null,
"country":"India",
"type":"Investor",
"sub_type":"Mutual Fund",
"is_client":0,
"pivot":{
"contact_id":8,
"company_id":7,
"created_at":"2017-07-01 17:07:08",
"updated_at":"2017-07-01 17:07:08"
}
}
]
},
{
"id":7,
"salutation":"Ms",
"first_name":"XYZ",
"last_name":"ABC",
"number":"1847171087",
"mobile":"8327523057",
"email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="becdd5dcd5d4d9dbccdcccdffedadfdcd8d2c8dad4d890ddd1d3">[email protected]</a>",
"alt_email":null,
"address":"Mumbai",
"city":"Mumbai",
"state":null,
"country":"India",
"profile":null,
"sectors_interested":"[\"Insurance\",\"Information Technology\",\"Infrastructure\",\"hevy machines\"]",
"companies_interested":"[6,4]",
"interactions_count":8,
"client_interactions_count":0,
"company":[
{
"id":3,
"name":"Franklin Fun",
"address":"Mumbai",
"city":"Mumbai",
"state":null,
"country":"India",
"type":"Investor",
"sub_type":"Mutual Fund",
"is_client":0,
"pivot":{
"contact_id":7,
"company_id":3,
"created_at":"2017-07-01 16:59:41",
"updated_at":"2017-07-01 16:59:41"
}
}
]
}
]
}
I have a requirement to transform this data into another format, which should look like this:
return this.model.map(d => ({
name: d.first_name + ' ' +d.last_name,
company: d.company[0].name,
email: d.email,
mobile: d.mobile,
profile: d.profile,
count: d.interactions_count ? d.interactions_count : d.client_interactions_count
}))
One key aspect is that if the interactions_count
value is 0, then it should be replaced with the client_interactions_count
. Additionally, I am facing some challenges in extracting the company name from the initial array parameter and sorting the output based on the count
field in descending order as per the response received. Any assistance or guidance on how to achieve this would be greatly appreciated. Thank you.