Inside one resolver I need to get user data. First I need to check if its profile is 'Sales' if yes, using the username returned I have to get the salesPerson data from other http get method, or else, returns some data I can check if is empty.
I have 2 different methods:
userInfo(): Observable<User> {
return this.httpClient.get('/endpoint/api/auth/me')
.pipe(
map(result => result['user'])
)
} // in this observable there is the username and profile inside.
getSalesPerson(username) {
return this.httpClient.get<ISalesRep>(`${this.BASE_URL}/getVendedor?user=${usuario}`);
} // is this observer there is salesPerson data with SalesPersonId
The observer of both are different. First question: on resolve method of resolver, what should be the type to use? The first one uses IUSer interface and second uses ISalesRep interface.
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
Observable<????> | Promise<????> | ??? { ... }
The second question: How can make the return?
return this.loginService.userInfo()
.pipe (
???someMethod???((user) => {
if ( user.profile == 'Sales' ) {
return this.otherService.getSalesPerson(user.username)
.subscribe((data) => { take the SalesPerson Observable }
} else {
return empty observable or some I can check if is empty;
}
})
)
.subscribe();
I apretiate someone can help. Thanks in advance