функции firebase с ошибками [Обещания должны быть обработаны соответствующим образом] при развертывании

Вы будете пинать себя:

while( ( $pass < 3 ) && ( $result = 0 ) ) {

Должен использовать двойной эквивалент - это сравнение, а не назначение:

while( ( $pass < 3 ) && ( $result == 0 ) ) {
0
задан Sadegh 20 January 2019 в 08:19
поделиться

1 ответ

Ваш код немного запутан, и его не так просто понять, не посвящая много времени.

Однако ниже приведен фрагмент кода, который должен работать и охватывать один случай вашей бизнес-логики. Обратите внимание, как возвращаются обещания, возвращаемые асинхронными задачами.

  export const sendChatNotification = functions.firestore
      .document('rooms/{roomId}/messages/{messageId}')
      .onCreate((snap, context) => {
        const roomId = context.params.roomId;
        const messageId = context.params.messageId;

        const newValue = snap.data();

        const receiverId = newValue.receiverId;
        const text = newValue.text;
        const type = newValue.type;
        const senderName = newValue.senderName;

        var p = admin
          .firestore()
          .collection('users')
          .doc(receiverId)
          .get();

        return p.then(snapshot2 => {  // <- HERE, the promise is returned
          const data2 = snapshot2.data();
          const firebaseNotificationToken = data2.firebaseNotificationToken;

          if (type == 'voiceCall' || type == 'videoCall' || type == 'hangUp') {
            const channelId = newValue.channelId;
            const senderId = newValue.senderId;
            const status = newValue.status;

            console.log('type: ' + type + ' /status: ' + status);

            let message = {
              data: {
                type: type,
                senderId: senderId,
                senderName: senderName,
                receiverId: receiverId,
                status: status,
                channelId: channelId,
                roomId: roomId
              },
              token: firebaseNotificationToken
            };

            return admin.messaging().send(message);  // <- HERE, the promise is returned
          }
        });

  }); 

Я бы посоветовал вам посмотреть 3 видео о «Обещаниях JavaScript» из серии видеороликов Firebase: https://firebase.google.com/docs/functions/video-series/ [ 114]

0
ответ дан Renaud Tarnec 20 January 2019 в 08:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: