Can someone help me with two requests?
/users
and /user/<id>/milpac
/users
returns a list of User[]
, while /user/<id>/milpac
returns a milpac object.
export class User {
join_date: string;
promotion_date: string;
user_id: number;
username: string;
milpac: Milpac;
}
export class Milpac {
user_id: number;
milpac_id: number;
real_name: string;
username: string;
rank: string;
rank_shorthand: string;
status: string;
primary_position: string;
bio: string;
join_date: string;
promotion_date: string;
}
First, I fetched all users using:
getAll(): Observable<User[]> {
const headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': this.API_AUTH_HEADER
});
const options = { headers: headers };
return this.http.get<UserResult>(this.API_URL + '/users/active', options).pipe(map(r => r.data.users));
}
Later on, there was a need to load a milpac information into a User object:
getMilpac(userId: number): Observable<Milpac> {
const headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': this.API_AUTH_HEADER
});
const options = { headers: headers };
return this.http.get<MilpacResult>(this.API_URL + `/user/${userId}/milpac`, options).pipe(map(r => r.data));
}
My goal now is to load a Milpac
object into a User
object, within an observable stream.
The final observable result should still be User[]
with populated fields from Milpac
.
I've heard about mergeMap functions but can't seem to implement them correctly. Any guidance would be appreciated!