Last active
April 23, 2019 12:43
-
-
Save Akshay090/b84a98e48d10f9be9377bf432501fdb2 to your computer and use it in GitHub Desktop.
counter cloud functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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