Tuesday, 14 March 2017

Getting AutoKey with Firebase Function

i am trying to get auto key with firebase functions.

event.data.key doesn't return the key. How can i listen isEnabled and when changed it true, add another data to notification ref with same key.

exports.sendNotificationWhenEnabled = functions.database.ref('/contents/{contentId}/isEnabled').onWrite(event => {
  const isEnabled = event.data.val();
  const contentId = event.data.key;
  admin.database().ref('/contents/' + contentId).once('value', function(snapshot) {
      console.log('Sending Notification to: ', contentId);
      admin.database().ref('/notifications/' + contentId).push({
        'asd': 'asd'
      }).then(snapshot => {
        console.log('finished');
      });
    });
    return "FINISHED";
  }
});



via Brkr

No comments:

Post a Comment