Skip to content

Instantly share code, notes, and snippets.

@Akshay090
Last active April 23, 2019 12:43
Show Gist options
  • Save Akshay090/b84a98e48d10f9be9377bf432501fdb2 to your computer and use it in GitHub Desktop.
Save Akshay090/b84a98e48d10f9be9377bf432501fdb2 to your computer and use it in GitHub Desktop.
counter cloud functions
exports.genderCountFxn = functions.database
.ref("/atEvent/{date}/{id}")
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const Visitor = snapshot.val();
console.log("Inside Visitor Fxn");
console.log(Visitor);
console.log(Visitor.name);
//---------------------------------------------------
//Working gender counter
const genderCountersRef = admin
.database()
.ref(`count/${Visitor.gender}`);
return genderCountersRef
.transaction(counter_value => {
return (counter_value || 0) + 1;
})
});
//To deploy firebase deploy --only functions:genderCountFxn
exports.overallCountFxn = functions.database
.ref("/atEvent/{date}/{id}")
.onCreate((snapshot, context) => {
const Visitor = snapshot.val();
const overallCountersRef = admin
.database()
.ref(`count/overAllTotal`);
return overallCountersRef
.transaction(counter_value => {
return (counter_value || 0) + 1;
})
});
//To deploy firebase deploy --only functions:overallCountFxn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment