Sequential execution

Asked

Viewed 57 times

1

I am new to the world of angular and Ionic. I have a main function that executes a command in the bank if this command gives error it calls another function . So far so good, only that this function that is called does not perform in the correct way, because inside it I call a function that does an update in the local bank, only that this function is only executed even when it reads all the lines of this function, Even though I put this function in the first line of my method, it only performs at the end. It’s like ignoring the function and executing all the other lines and when all the other lines are executed there yes it performs my function. Did you understand ? Does anyone know why this happens? Follow the codes.

 if (this.conectividade.isOnlineCheck()) {
    this.web_service_romaneio.confirmacaoBaixa(body).subscribe(data => {
      if (data == true) {
         //successs
      } else {
        alert(JSON.stringify(data));
      }
    }, erro => {
      erro = true;
    });

  } else {
    //Essa eh a funcao que chamo 
    this.salvarOffLine(this.id_romaneio);
  }
  if (erro) {
    //Essa eh a funcao que chamo 
    this.salvarOffLine(this.id_romaneio);
  } else {

  }

 // Essa eh funcao que chama la em cima e que so executa o update no banco quando acaba a funcao

 salvarOffLine(id) {

   this.loading2 = this.loadingCtrl.create({
      content: 'Nao foi possivel conectar ao servidor. Salvando dados para uma proxima conexão.'
  });
  this.loading2.present();
 // FUncao que eh ignorada
  this.retornoUpdate = this.bd_local.updateRomaneioConfirmacao(id, 0);
  alert(JSON.stringify(this.retornoUpdate));
  this.loading2.dismiss();
 }

And that’s the code of the function that is "ignored", which is inside a provider.

   updateRomaneioConfirmacao(codigo, flag) {
/*
0 - Para identificar que a nota nao foi baixada no webservice pois ocorreu um erro de conexao
1 - Para identificar que a nota foi baixada corretamente
 */
this.sqlite.create({
  name: 'infoged.db',
  location: 'default'
}).then((db: SQLiteObject) => {
  db.executeSql("UPDATE tb_romaneio SET romaneio_statusEntrega = 1, romaneio_sincronizada ="+ flag +" where id_romaneio = '" + codigo + "'", [])
    .then(ed => alert(JSON.stringify(ed)))
    .catch(e => alert(JSON.stringify(e)));
}).catch(e => alert(JSON.stringify(e)));

}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.