Reputation: 437
I want to replace subscribe in subscribe by switchMap, i dont know how to do that. I need 1 example, but i didn't find it on the Internet.
dialogRef.afterClosed().pipe(filter(result => !!result)).subscribe(result => {
result.owner = this.user.id;
proj._newname = result.name;
proj.name = result.name;
this.projectService.updateProject(proj, result.name)
.subscribe(project => {
const pw = new ProjectWorker({
approve: true,
worker: this.user.id,
project: project.id,
admin: true,
write: true
});
this.projectService.createProjectWorker(pw).subscribe(_ => {
this.getProjects();
});
},
err => {
this._snackbar.open('Project already exist', 'error', {
panelClass: 'snackbar-error'
})
});
}
);
Upvotes: 1
Views: 556
Reputation: 40647
Something like this:
dialogRef.afterClosed().pipe(
filter(result => !!result),
switchMap((result) => {
result.owner = this.user.id;
proj._newname = result.name;
proj.name = result.name;
return this.projectService.updateProject(proj, result.name);
}),
switchMap((project) => {
const pw = new ProjectWorker({
approve: true,
worker: this.user.id,
project: project.id,
admin: true,
write: true
});
return this.projectService.createProjectWorker(pw);
}),
).subscribe(
res => this.getProjects(),
err =>
this._snackbar.open('Project already exist', 'error', {
panelClass: 'snackbar-error'
})
);
Upvotes: 1