I make a post to the database, I must make a map to treat the response of that query, if in the response one of the data that I need does not come, I must make another query, I do this query with an await / async but it does not seem to work when I debug. The code as the following:
// Service (I have changed the endpoints)
public login(username: string, password: string) {
let loginDto = { info: new LoginDto(username, password) };
return this.http.post('https://jsonplaceholder.typicode.com/posts', { title: 'Angular POST Request Example' }).pipe(
map(response => {
return this.processLoginResponse(response);
})
);
}
private async processLoginResponse(response) {
let permissions = await this.getPermissionsFromAPI(116677);
this._user = {username: 'Jhon', permissions: permissions};
return this._user
}
private getPermissionsFromAPI(userId): Promise<any> {
return this.http.get('https://jsonplaceholder.typicode.com/todos/1').toPromise();
}
// Component
onSubmit(e) {
const { username, password } = this.formData;
this.authService
.login(username, password)
.subscribe(
data => {
data.then(x => console.log(x));
// things
}
);
}