Skip to content

Instantly share code, notes, and snippets.

@horacioibrahim
Created December 4, 2016 18:56
Show Gist options
  • Select an option

  • Save horacioibrahim/f4778164104cdbd415b2785b09b1e657 to your computer and use it in GitHub Desktop.

Select an option

Save horacioibrahim/f4778164104cdbd415b2785b09b1e657 to your computer and use it in GitHub Desktop.
firebase.database().ref('transactions/').push(data).then(function(res){ // PUSH 1
firebase.database().ref('users/' + user.uid + '/transactions/' + res.key).set({dtCreated: data.dtCreated}).then(
function(res2){ // AFTER PUSH 2
console.log("Gravou nos 2");
window.location.href = "#/dashboard/history";
}, function(err2) {
var error = {
canceled: true,
log: "transaction not registered in owner attributes."
};
// WORKAROUND IF ERROR
firebase.database().ref('transactions/' + res.key).update(error).then(function(resRemoved){
console.log("removido!" + resRemoved);
});
toast.message = "Problemas ao gravar sua transação";
tpl.toastOn();
}
);
}, function(err) {
console.log(err);
toast.message = "Problema ao gravar a transação";
tpl.toastOn();
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment