I am new to Firebase cloud functions. I would like to have a function in index.js that trigger when a node in database is created - 1. it will take the params of the context 2. and find a value of a node, 3. get value from another database, 4. adding that value to 3 diff places.
exports.runningNumber = functions.database.ref("Main/Enemy/{enem_Id}/{event_Id}"}
.onCreate((snapshot, context) => {
var enemid = context.params.enem_Id;
var eventid = context.params.event_Id;
return admin.database().ref("Main/Enemy/" + enemid + "/SequenceNumber").once('value', (snapshot) => {
var newSeqNum = snapshot.val() + 1;
//then, get var userid through database().ref("Main/Enemy/" + enemid + "/" + eventid + "/user_Id")
//and then, use newSeqNum to:
//1. Replacing "Main/Enemy/" + enemid + "/SequenceNumber"
//2. Adding as string into "Main/Enemy/" + enemid + "/" + eventid + "/SeqNum"
//3. Adding as string into "Main/Users/" + userid + "/" + eventid + "/SeqNum"
});
});
Hope somebody can help on how to do this...