One of my APIs/projects returns a JSON dataset like this:
[
{
"id":100,
"name":"some name",
"x": "y"
},
{
"id":200,
"another name",
"x": "z"
}
]
Another API/costs call returns a similar dataset:
[
{
"projectid":100,
"cost":300
},
{
"projectid":100,
"cost":100
},
{
"projectid":200,
"cost":500
}
]
I initially wrote a messy code using ajax/jquery/JS to create a JavaScript object with "id", "name", and the total "cost". I then converted it into a JSON object.
As the queries became more complex, I found it inefficient and almost impossible to handle with raw JS. So, I decided to switch to Angular services, as they are easier to integrate for the front-end team.
Although I have little experience with Angular, I have created a simple service to query all projects or a single project based on its ID.
My question is, can Angular be used to query the APIs and generate a JSON that includes only the name and id from the first query, and calculates the total cost for each project from the second query? The desired output should be:
[
{
"id":100,
"name":"some name",
"cost":400
}
]
[
{
"id":200,
"name":"another name",
"cost":200
}
]
Thanks!