I have an API that returns data such as this:
{
"attributes": {
"type": "Opportunity"
},
"Amount": 175.36,
"Owner": {
"attributes": {
"type": "User"
},
"Name": "Steve Knight"
}
},
{
"attributes": {
"type": "Opportunity"
},
"Amount": 6800,
"Owner": {
"attributes": {
"type": "User"
},
"Name": "Bob Smith"
}
}
etc...
These represent opportunities and so each salesperson will have multiple. I am trying to return an object that sums the amounts for each salesperson and returns something like:
{Steve Knight: 5590, Bob Smith: 98722, John Jones: 12347893}
I have tried grouping the objects by owner name however I am not sure how to then sum the amounts
var groupBy = require('lodash.groupby');
var grouped = groupBy(data, function(x) {
return x.Owner.Name;
});