Skip to content

Instantly share code, notes, and snippets.

@nhathiwala
Created August 12, 2017 07:39
Show Gist options
  • Select an option

  • Save nhathiwala/7c34e51487f12abd81635b2326514611 to your computer and use it in GitHub Desktop.

Select an option

Save nhathiwala/7c34e51487f12abd81635b2326514611 to your computer and use it in GitHub Desktop.
firefunctions/src/triggers/index.ts
/*
* FILE NAME: index.ts
* FILE PATH: './triggers/'
* AUTHOR: NAYAN HATHIWALA
* CREATED ON: 10/8/2017
* DESCRIPTION: BASE TRIGGER.
*/
/*
* IMPORT LIBRARY HERE
*/
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
/*
* Below you can write your triggers
*/
// Source: https://firebase.google.com/docs/functions/database-events
export const makeUppercase = functions.database.ref('/messages/{pushId}/original').onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
const original = event.data.val();
console.log('Uppercasing', event.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return event.data.ref.parent.child('uppercase').set(uppercase);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment