I have a data like below:
const Users =
{
"users": [
{
"id": "person1",
"information": [
{
"first_name": "Mike",
"last_name": "Patty",
"address": ["address1","address2"]
},
{
"first_name": "Mike2",
"last_name": "Patty2",
"address": ["address1","address2"]
}
]
},
{
"id": "person2",
"information": [
{
"first_name": "Tom",
"last_name": "Jerry",
"address": ["address1","address2"]
},
{
"first_name": "Tom2",
"last_name": "Jerry2",
"address": ["address1","address2"]
}
]
}
]
}
I would like to iterate users and add each user's information to the API database.
addInforequest requires:first_name,last_nameandaddress(addressis array).Each
this.APIservice.addInformation()will return one response, I will need the response later
How do I collect all response from all information for the same users and get in a format like:
// should return two object/array, each object/array collects all response from information for the same person.
person1:
["response from Mike Patty", "response from Mike2 Patty2"]
person2:
["response from Tom Jerry", "response from Tom2 Jerry2"]
here is what I am trying to code so far:
// add information
const addUsers$ = forkJoin(
Users.users.map(person =>
person.information.map(info =>
this.APIservice.addInformation(
{
firstName: info.first_name,
lastName: info.last_name,
address: info.address
})
)
)
);
otherFunction$. // this needs to run first
.pipe(
mergeMap(() => addUsers$)
tap(console.log),
// I need to manipulate res later here
).subscribe(() => console.log("finish"))
}
The error with current codes:
TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
Thank you in advance!