I'm currently trying to learn Firebase functions. This new feature seems to be pretty powerful and useful.
I'd like to use a function the catch a DB writing event, make a comparison with a specific location in DB and then write some data (depending on the comparison result) in another location in DB.
Here's my current Node.js code:
exports.verificaFineLavoro = functions.database.ref('/Aziende/{nomeazienda}/LogAsegno/{pushidbracciante}/{pushidlog}/Asegno')
.onWrite(event => {
const original = event.data.val();
console.log('VerificaFineLavoro', event.params.pushId, original);
const aSegno = original;
console.log('aSegno', aSegno +"");
const FineLavoro = ref.parent.parent.parent.parent.child("Asegno/"+aSegno+"/FineLavoro");
return event.data.ref.child('FL').set(FineLavoro);
});
Currently the function gets triggered but it stops working because of the references which are probably wrong.