Функция Firebase: не может прочитать 'user_id' из неопределенного - PullRequest
0 голосов
/ 23 сентября 2018

Я пытаюсь реализовать функцию отправки push-уведомлений с одного устройства на другое устройство с помощью моего мобильного приложения.Ссылаясь на видео уроки.Это мой текущий код JavaScript:

'use-strict'

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.firestore.document("users/{user_id}/notification/{notification_id}").onWrite(event=> {

const user_id = event.params.user_id;
const notification_id = event.params.notification_id;
return admin.firestore().collection("users").doc(notification_id).get().then(queryResult=> {

        const from_user_id = queryResult.data();
        const from_data = admin.firestore().collection("users").doc(from_user_id).get();
        const to_data = admin.firestore().collection("users").doc(user_id).get();
        return Promise.all([from_data, to_data]).the(results =>{
            const from_name = results[0].data().name;
            const to_name = results[1].data().name;
            console.log("from :"+ from_name+" To "+ to_name);
        });


    });
});

Это показывает следующую ошибку

TypeError: Cannot read property 'user_id' of undefined at exports.sendNotification.functions.firestore.document.onWrite.event (/user_code/index.js:9:30)
at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23)
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20)
    at /var/tmp/worker/worker.js:733:24
    at process._tickDomainCallback (internal/process/next_tick.js:135:7 

Пожалуйста, помогите мне.

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