Currently, I am facing a challenge in merging two API calls. The first call involves fetching data by filtering the account_id on the backend, while the second call retrieves data based on the test_id.
Let's start with the JSON response for /api/test-overview:
{
testSprint: [
{
account_id: 27,
test_id: 3,
name: "Junior"
},
{
account_id: 27,
test_id: 50,
name: "Wilson"
}
]
}
When the test_id is 3, the JSON structure for activityAvgService looks like this:
{
test_id: "3",
stats: {
avgE: 2.5,
avgD: 43.3,
avgA: 5.7,
avgH: 6.3,
highH: 0
}
}
Similarly, when the test_id is 50, the JSON response is as follows:
{
test_id: "50",
stats: {
avgE: 1,
avgD: 33,
avgA: 3,
avgH: 1,
highH: 0
}
}
In my controller, I have implemented a $http request to fetch the initial /api/test-overview data. Following are the essential steps:
$http.get("/api/test-overview").then(testResponse => {
$scope.test = testResponse.data.testSprint;
for (var i = 0; i < $scope.test.length; i++) {
activityAvgService.showStatsAVG($scope.test[i].test_id).then(response => {
var stats = response.data.stats
console.log("stats", stats);
});
}
});
The ultimate goal here is to merge all three JSON responses into the original /api/test-overview JSON. Ideally, the combined JSON should look like this:
{
testSprint: [
{
account_id: 27,
test_id: 3,
name: "Junior",
stats: {
avgE: 2.5,
avgD: 43.3,
avgA: 5.7,
avgH: 6.3,
highH: 0
}
},
{
account_id: 27,
test_id: 50,
name: "Wilson",
test_id: "50",
stats: {
avgE: 1,
avgD: 33,
avgA: 3,
avgH: 1,
highH: 0
}
}
]
}
I have attempted using map and concat methods but without success. Any fresh ideas or insights on how to proceed would be greatly appreciated!
Thank you in advance for your assistance!