I want to run a combined operation to remove 2 nodes on Firebase in one operation. I know there is remove() to remove node if I have the node location. But what is remove() operation return? An promise or an observable? How do I know the remove operation is successful so I can run the other remove operation or tell my component the remove operation is successful (or there is an error)?
Example provide (need help on multi-location delete help with AngularFire):
constructor(private db:AngularFireDatabase, @Inject(FirebaseRef) fb) {
this.sdkDb = fb.database().ref();
}
deleteTask(taskId: string, jobtypeId: string): boolen {
const taskObservable = this.db.object('tasks' + '/' + taskId);
const taskPerJobtypeObervable = this.db.object('tasksPreJobtype' + '/' + jobtypeId + '/' + taskId);
taskObservable.remove()
.then(_ => {
console.log('success');
taskPerJobtypeObervable.remove()
.then(_ => {
return ture
});
})
.catch(err => {console.log(err, 'You dont have access!'), return false});
}
As you see I need to chain the remove as a promise, which I really want to avoid. I want this to be observable pattern as why I use angularFire2. So instead of return a boolean, I want to return an observable. And I want this to be multi-location delete. How can I refactor this code? Thank you so much!