Problem with update ionic + firestore

0

I get the image error when trying to perform an update on the database. The case is as follows, the user views an ad, and receives a value of 0.03 cents (this is symbolic). So the first time he gets the 0.03 he clicks to save data to write to the bank, so that's fine. Then if the value is greater than 0.03 it will update its value, then see another ads receive + 0.03 and save again, updating the value. For this I created two functions, one that adds and one that updates the value, when I try to update it shows the error of the image, I can not find out where I went wrong.

My code:

    //adiciona o valor ao banco de dados
    adicionarRecompensa() {
      this.recompensa.recompensaSalva = true;
      this.recompensa.valor = this.recompensaAcumulada;
      this.providerRecompensa.adicionarRecompensa(this.recompensa);
        this.toastAddRecompensa();
    }


    //atualiza o valor no banco de dados
    atualizarRecompensa(recompensa: Recompensa) {
       this.providerRecompensa.atualizarRecompensa(this.recompensa.id, 
       this.recompensa);
         this.toastAtualizarRecompensa();
    }


    //grava a recompensa no banco de dados
    salvarRecompensa() {
       //se o valor for igual a 0.03 ele adiciona ao banco
       if(this.recompensa.valor == 0.03 || NaN){
          this.adicionarRecompensa();
       }

       //se o valor for maior que 0.03 ele faz update toda vez que o usuario 
       clicar em salvar recompensa
       if(this.recompensa.valor > 0.03){
         this.atualizarRecompensa(this.recompensa);
       }

    }




   //PROVIDER 
   import { Injectable } from '@angular/core';
   import { AngularFirestore, AngularFirestoreCollection } from 
           'angularfire2/firestore';
   import { Observable } from 'rxjs/Observable';
   import { LoginProvider } from '../../providers/login/login';
   import { Recompensa } from '../../models/recompensa';

   @Injectable()

       export class RecompensaProvider {

       recompensaSalva = true;
       private caminho: string = '';
       private recompensaColllection: 
       AngularFirestoreCollection<Recompensa>;
       recompensas: Observable<Recompensa[]>;

       constructor(private afs: AngularFirestore, private login: 
                   LoginProvider) {

          this.login.usuario.subscribe(auth => {
             if(auth != null)
            {
               this.caminho = '/' + auth.email ;
               this.recompensaColllection = afs.collection<Recompensa> 
                   (this.caminho, ref => {
              return ref;
            });
            } else {
               this.caminho = '';
           }
        });
      }


    // Método usado para adicionar uma recompensa
   adicionarRecompensa(recompensa: Recompensa) {
     this.recompensaColllection.add(recompensa);
   }


   //Método usado para atualizar a recompensa
   atualizarRecompensa(id: string, recompensa:Recompensa) {
     this.recompensaColllection.doc(id).update(recompensa);
   }


   // Este método será retorna uma lista das recompensas
   buscarRecompensa(recompensaSalva: boolean) {
      return this.afs
      .collection<Recompensa>(this.caminho, ref => {
      return ref.where('recompensaSalva', '==', recompensaSalva);
      })
        .snapshotChanges()
        .map(actions => {
        return actions.map(a => {
        const data = a.payload.doc.data() as Recompensa;
        const id = a.payload.doc.id;
        return { id, ...data };
      })
    });
   }


}
    
asked by anonymous 02.11.2018 / 13:09

0 answers