Функция Firecloud не запущена? - PullRequest
0 голосов
/ 30 октября 2019

Это моя функция, она даже не запускается облаком функций Firebase! я получаю сообщение об ошибке: Ошибка: не удалось выполнить функцию. Подробности: Не удается прочитать свойство 'ref' из неопределенного

     //send the push notification 
    exports.sendPushNotification = functions.database.ref('contacts/').onCreate(event => {

      const root = event.after.ref.root
      var messages = []

      //return the main promise 
      return root.child('/users').once('value').then(function (snapshot) {
          snapshot.forEach(function (childSnapshot) {

              var expoToken = childSnapshot.val().expoToken;

              messages.push({
                  "to": expoToken,
                  "sound": "default",
                  "body": "New Note Added"
              });
          });
          //firebase.database then() respved a single promise that resolves
          //once all the messages have been resolved 
          return Promise.all(messages)

      })
          .then(messages => {
              // console.log(messages)
              fetch('https://exp.host/--/api/v2/push/send', {
                  method: 'POST',
                  headers: {
                      'Accept': 'application/json',
                      'Content-Type': 'application/json',
                  },
                  body: JSON.stringify(messages)

              });
          })
          .catch(reason => {
              console.log(reason)
          })


    });

1 Ответ

1 голос
/ 30 октября 2019

onCreate было изменено на следующее:


exports.sendPushNotification = functions.database.ref("contacts/").onCreate((snap, context) => {
  const createdData = snap.val();

В вашем случае, чтобы получить root, сделайте следующее:

const roots = snap.ref.root

Вы можете найти больше информации здесь:

https://firebase.google.com/docs/functions/beta-v1-diff

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...