Home » Javascript » Firebase cloud functions nested then writes

Firebase cloud functions nested then writes

Posted by: admin August 19, 2018 Leave a comment

Questions:

I’m writing an app which requires me to validate transactions and log them. Some of the code in my functions looks like this:

snapshot.after.ref.parent.parent.child('liquidAssets').set(newLiquidAssets).then( function(){
                snapshot.after.ref.parent.parent.child('transactions').push({
                timestamp: tinestampOfTransaction,
                transaction: transaction,
                stock: tickerSymbol,
                volume: sharesToBuy,
                price: currPrice
              }).then( function(){
                return 1;
              });
            });

I only want to add the transaction log after the set is completed. After the push I want to return 1. When uploading the code it says that it expects a catch or return here.

Answers: