0

This question is continuation of this stack overflow question

this.firestoreService.addMessage(message) does not add the message to the database

addMessage() returns before executing tap((user) => console.log(user)),

   submit() {
     this.subscription = from(this.form.value.users)
      .pipe(
        finalize(() => {
          console.log('finalize'),
          this.dismiss()
        }),
        map(user => this.buildMessage(user)),
        switchMap((message) => this.firestoreService.addMessage(message))
      ).subscribe();

   }

  addMessage(data:Message):Observable<any> {
    console.log('addMessage');
    data.timestamp = firebase.firestore.FieldValue.serverTimestamp();
    return this.authService.currentUser$.pipe(
      tap((user) => console.log(user)),
      switchMap(user => {
        console.log('addMessage user: ', user);
        if (user.company) {
          return from(this.firestore
            .collection<any>(user.company)
            .doc(user.licence)
            .collection<any>(message)
            .add(data))

        } else {
          return of([]);
        }
        }
      )
     );
   }
    
output: 'addMessage'

no output: tap((user) => console.log(user)),

this.authService.currentUser$

get currentUser$() {
    return this.angularFireAuth.user.pipe(
      tap((user) => console.log(user)),
      filter(user => !!user),
      switchMap(user => this.userService.user$(user.uid))
    );
  }
dak
  • 339
  • 6
  • 21
  • Did you review if `this.authService.currentUser$` emit any value? – Luis Reinoso Oct 22 '20 at 13:20
  • Have you confirmed if you can [add data](https://firebase.google.com/docs/firestore/manage-data/add-data) to Cloud Firestore without using observables? This will help narrow down the cause of the issue. – tzovourn Oct 22 '20 at 14:47
  • I have updated the question with currentUser$() code which does log a value. Data can be added to the database without using observables. – dak Oct 22 '20 at 14:54

0 Answers0