我当前正在开发约会应用程序,并且通知是该应用程序之一。结果,我一直在使用firebase函数来通知用户是否有新的约会被预定或取消。我收到未定义ReferenceError:事件的错误 Node.js代码
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Notifications/{PostKey}/{notification_id}').onWrite((data, context) => {
const user_id = context.params.PostKey;
const notification_id = context.params.notification_id;
console.log('We have a notification from : ', user_id,'this also notification_id',notification_id);
if(!event.data.val())
{
return console.log('A Notification has been deleted from the database : ', notification_id);
}
const deviceToken = admin.database().ref(`/User_Data/${user_id}/Device_Token`).once('value');
console.log('A Notification has been deleted from the database : ', deviceToken);
return deviceToken.then(result => {
const token_id = result.val();
const payload =
{
notification:
{
title:"Appointment has been booked",
body: "one of your Appointmtnt has been booked",
icon:"default"
}
};
return admin.messaging().sendToDevice(token_id,payload).then(response =>
{
return console.log('This was the notification Feature');
});
});
});
错误日志 ReferenceError:事件未定义 在export.sendNotification.functions.database.ref.onWrite(/user_code/index.js:16:9) 在cloudFunctionNewSignature(/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23) 在cloudFunction(/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20) 在/var/tmp/worker/worker.js:733:24 在process._tickDomainCallback(内部/进程/next_tick.js:135:7) **数据库结构**
答案 0 :(得分:0)
错误消息非常准确。告诉您在第16行使用了一个名为event
的变量,但从未定义它:
if(!event.data.val())