0

API returns an array of JSON Objects.

[
{
    "vacancy": "61a6597b0dc105d6e79a1f30",
    "createdBy": "61aa11644afa183fa28b0792",
    "executor": "61aa20ee25ef06b69920a505",
    "reviewer": "61aa11644afa183fa28b0792",
    "status": "Invited",
    "_id": "61aa213aeaf2af804aa1e591",
    "createdAt": "2021-12-03T13:52:58.772Z",
    "updatedAt": "2021-12-03T13:52:58.772Z"
},
...
]

And I need convert some propertys in to objects by making get request with value. Something like that:

this.http.get<Application>(
      `${environment.API_ENDPOINT}/applications/assigned?status=completed`
    ).pipe(
        map(aplication => 
{
...aplication,
vacancy:this.http.get(`${environment.API_ENDPOINT}/vacancys/`+ aplication.vacancy),
executor:this.http.get(`${environment.API_ENDPOINT}/candidates/`+ aplication.executor)
}
    )
1

1 Answer 1

2

You need to use a "Higher Order Mapping Operator", which will internally subscribe to an observable and emit its emissions.

In your case, switchMap will work for this. Since you need to make two different calls, we can use forkJoin to create an observable that will emit both results when they are received:

myObj$ = this.http.get<Application>('/applications/assigned').pipe(
    switchMap(aplication => forkJoin({
        vacancy  : this.http.get(`environment.API_ENDPOINT}/vacancys/${vacancy}`),
        executor : this.http.get(`environment.API_ENDPOINT}/candidates/${executor}`)
    }).pipe(
        map(({vacancy, executor}) => ({...aplication, vacancy, executor})
    ))
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.