I am building an app with node.js, mssql (don't ask.. client), socket.io and angularjs.
I have managed to get data from mssql to angular in the following form.
[
{
"measure":"value",
"region":"London",
"manager":"Jack",
"supervisor":"James",
"number1":44,
"number2":2244.3,
"number3":1561.6
},
{
"measure":"value",
"region":"London",
"manager":"Jack",
"supervisor":"Jerry",
"number1":335.4,
"number2":33.3,
"number3":11.6
},
{
"measure":"value",
"region":"London",
"manager":"John",
"supervisor":"Joseph",
"number1":444.3,
"number2":233,
"number3":1561.6
}
]
I am trying to manipulate the data through angular.forEach to achieve the following result:
[
{
"region": "London",
"regionTotals" : {
"turnover" : {
"number1" : "TOTAL OF NUMBER 1 WITH REGION LONDON",
"number2" : "TOTAL OF NUMBER 2 WITH REGION LONDON",
"number3" : "TOTAL OF NUMBER 3 WITH REGION LONDON"
}
},
"managers" : {
"jack" : {
"managerTotals" {
"number1": "TOTAL OF NUMBER 1 WITH MANAGER JACK",
"number2": "TOTAL OF NUMBER 2 WITH MANAGER JACK",
"number3": "TOTAL OF NUMBER 3 WITH MANAGER JACK"
},
"supervisors" : {
"Jerry": {
"supervisorTotals" : {
"number1":335.4,
"number2":33.3,
"number3":11.6
}
},
"James": {
"supervisorTotals" : {
"number1":44,
"number2":2244.3,
"number3":1561.6
}
}
}
},
"john" : {
"managerTotals" {
"number1": "TOTAL OF NUMBER 1 WITH MANAGER JOHN",
"number2": "TOTAL OF NUMBER 2 WITH MANAGER JOHN",
"number3": "TOTAL OF NUMBER 3 WITH MANAGER JOHN"
},
"supervisors" : {
"Joseph": {
"supervisorTotals" : {
"number1":444.3,
"number2":233,
"number3":1561.6
}
}
}
}
}
}
]
Is this the best way to do this? And if you have any advice on how to run it through a javascript loop it would be much appreciated as I'm struggling big time. Especially trying to set the object keys.
The only other way I can think of doing it is running a bunch of queries in node and putting it together server side rather than client side. However considering I'm using mssql I wanted to keep queries to a bare minimum.
Thanks