Let's say I have a Student with two properties: courseIds, courses.
export interface IStudent {
courseIds: number[];
courses: ICourse[];
}
export interface ICourse {
name: string;
}
When the page loads I issue a GET request to retrieve a Student where only the courseIds are populated. Then I want to validate these Id's and make an unknown number of aditional GET requests to a diferent endpoint to retrieve his Courses.
In the end I want to have a Student object with populated Courses array.
I got this far:
httpClient.get<IStudent>(url)
.pipe(
map(student => {
const validIds = [];
student.courseIds.forEach(id => {
if (isValid(id)) {
validIds.push(id);
}
}
return validIds;
}),
???
).subscribe(
???
);
Question marks indicate where I'm stuck. How can I implement this using Observables?