Last active
March 14, 2017 06:39
-
-
Save DennisAlund/1b6a5eedf32b2d192f74fc6b1c98c542 to your computer and use it in GitHub Desktop.
Gist for medium article https://medium.com/evenbit/firebase-cloud-functions-on-the-clock-312d7c14327
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
| import * as functions from "firebase-functions"; | |
| import * as admin from "firebase-admin"; | |
| admin.initializeApp(functions.config().firebase); | |
| export const onCreated = functions.database.ref("timings/{id}/created").onWrite(event => { | |
| return event.data.ref.parent.child("handled").set(admin.database.ServerValue.TIMESTAMP); | |
| }); | |
| export const onHandled = functions.database.ref("timings/{id}").onWrite(async event => { | |
| const entry = event.data.val(); | |
| if (!entry.handled) { | |
| return; | |
| } | |
| return admin.database().ref("durations").child(event.params.id).set(entry.handled - entry.created); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment