Cannot read property 'From' of undefined at /user_code/index.js
I am working on sending notification between two applications. I have tried to do this through node.js but now I am stuck at this error for 1 month but found no solution to it.please help me out in it. this is very important for me.I will be very thankful for any kind of help.
"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}/Notifications/{notification_id}').onWrite((change, context) => {
const user_id= context.params.user_id;
const notification_id= context.params.notification_id;
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc("notification_id").get().then(querySnapshot => {
const from_user_id= querySnapshot.data().From;
const from_message= querySnapshot.data().message;
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]).then(result => {
const from_name=result[0].data().name;
const to_name=result[1].data().name;
const token_id= result[1].data().token_id;
const payload= {
notifications:{
title: "Notification from : " + from_name,
body: from_message,
icon:"default"
}
};
return admin.messaging().sendToDevice(token_id, payload).then(result => {
return console.log("Notification Sent");
});
});
});
here is the monstrous error`
node.js google-cloud-functions
add a comment |
I am working on sending notification between two applications. I have tried to do this through node.js but now I am stuck at this error for 1 month but found no solution to it.please help me out in it. this is very important for me.I will be very thankful for any kind of help.
"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}/Notifications/{notification_id}').onWrite((change, context) => {
const user_id= context.params.user_id;
const notification_id= context.params.notification_id;
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc("notification_id").get().then(querySnapshot => {
const from_user_id= querySnapshot.data().From;
const from_message= querySnapshot.data().message;
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]).then(result => {
const from_name=result[0].data().name;
const to_name=result[1].data().name;
const token_id= result[1].data().token_id;
const payload= {
notifications:{
title: "Notification from : " + from_name,
body: from_message,
icon:"default"
}
};
return admin.messaging().sendToDevice(token_id, payload).then(result => {
return console.log("Notification Sent");
});
});
});
here is the monstrous error`
node.js google-cloud-functions
add a comment |
I am working on sending notification between two applications. I have tried to do this through node.js but now I am stuck at this error for 1 month but found no solution to it.please help me out in it. this is very important for me.I will be very thankful for any kind of help.
"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}/Notifications/{notification_id}').onWrite((change, context) => {
const user_id= context.params.user_id;
const notification_id= context.params.notification_id;
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc("notification_id").get().then(querySnapshot => {
const from_user_id= querySnapshot.data().From;
const from_message= querySnapshot.data().message;
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]).then(result => {
const from_name=result[0].data().name;
const to_name=result[1].data().name;
const token_id= result[1].data().token_id;
const payload= {
notifications:{
title: "Notification from : " + from_name,
body: from_message,
icon:"default"
}
};
return admin.messaging().sendToDevice(token_id, payload).then(result => {
return console.log("Notification Sent");
});
});
});
here is the monstrous error`
node.js google-cloud-functions
I am working on sending notification between two applications. I have tried to do this through node.js but now I am stuck at this error for 1 month but found no solution to it.please help me out in it. this is very important for me.I will be very thankful for any kind of help.
"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}/Notifications/{notification_id}').onWrite((change, context) => {
const user_id= context.params.user_id;
const notification_id= context.params.notification_id;
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc("notification_id").get().then(querySnapshot => {
const from_user_id= querySnapshot.data().From;
const from_message= querySnapshot.data().message;
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]).then(result => {
const from_name=result[0].data().name;
const to_name=result[1].data().name;
const token_id= result[1].data().token_id;
const payload= {
notifications:{
title: "Notification from : " + from_name,
body: from_message,
icon:"default"
}
};
return admin.messaging().sendToDevice(token_id, payload).then(result => {
return console.log("Notification Sent");
});
});
});
here is the monstrous error`
"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}/Notifications/{notification_id}').onWrite((change, context) => {
const user_id= context.params.user_id;
const notification_id= context.params.notification_id;
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc("notification_id").get().then(querySnapshot => {
const from_user_id= querySnapshot.data().From;
const from_message= querySnapshot.data().message;
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]).then(result => {
const from_name=result[0].data().name;
const to_name=result[1].data().name;
const token_id= result[1].data().token_id;
const payload= {
notifications:{
title: "Notification from : " + from_name,
body: from_message,
icon:"default"
}
};
return admin.messaging().sendToDevice(token_id, payload).then(result => {
return console.log("Notification Sent");
});
});
});
"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}/Notifications/{notification_id}').onWrite((change, context) => {
const user_id= context.params.user_id;
const notification_id= context.params.notification_id;
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc("notification_id").get().then(querySnapshot => {
const from_user_id= querySnapshot.data().From;
const from_message= querySnapshot.data().message;
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]).then(result => {
const from_name=result[0].data().name;
const to_name=result[1].data().name;
const token_id= result[1].data().token_id;
const payload= {
notifications:{
title: "Notification from : " + from_name,
body: from_message,
icon:"default"
}
};
return admin.messaging().sendToDevice(token_id, payload).then(result => {
return console.log("Notification Sent");
});
});
});
node.js google-cloud-functions
node.js google-cloud-functions
asked Nov 20 '18 at 19:15
nageen nawaz
66
66
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your firestore query isn't returning anything; probably because either the document/collection doesn't exist.
Right off the bat, it stands out that your "notification_id" is queried as string, rather than the const you set earlier. It's kind of a gamble, but changing line 10 to this may help:
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc(notification_id).get().then(querySnapshot => {
I didnot get you. Can you please be specific with code ? Help me thankyou
– nageen nawaz
Nov 21 '18 at 0:09
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400001%2fcannot-read-property-from-of-undefined-at-user-code-index-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your firestore query isn't returning anything; probably because either the document/collection doesn't exist.
Right off the bat, it stands out that your "notification_id" is queried as string, rather than the const you set earlier. It's kind of a gamble, but changing line 10 to this may help:
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc(notification_id).get().then(querySnapshot => {
I didnot get you. Can you please be specific with code ? Help me thankyou
– nageen nawaz
Nov 21 '18 at 0:09
add a comment |
Your firestore query isn't returning anything; probably because either the document/collection doesn't exist.
Right off the bat, it stands out that your "notification_id" is queried as string, rather than the const you set earlier. It's kind of a gamble, but changing line 10 to this may help:
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc(notification_id).get().then(querySnapshot => {
I didnot get you. Can you please be specific with code ? Help me thankyou
– nageen nawaz
Nov 21 '18 at 0:09
add a comment |
Your firestore query isn't returning anything; probably because either the document/collection doesn't exist.
Right off the bat, it stands out that your "notification_id" is queried as string, rather than the const you set earlier. It's kind of a gamble, but changing line 10 to this may help:
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc(notification_id).get().then(querySnapshot => {
Your firestore query isn't returning anything; probably because either the document/collection doesn't exist.
Right off the bat, it stands out that your "notification_id" is queried as string, rather than the const you set earlier. It's kind of a gamble, but changing line 10 to this may help:
return admin.firestore().collection("ServiceProviders").doc(user_id).collection("Notifications").doc(notification_id).get().then(querySnapshot => {
answered Nov 20 '18 at 20:25
Art
47239
47239
I didnot get you. Can you please be specific with code ? Help me thankyou
– nageen nawaz
Nov 21 '18 at 0:09
add a comment |
I didnot get you. Can you please be specific with code ? Help me thankyou
– nageen nawaz
Nov 21 '18 at 0:09
I didnot get you. Can you please be specific with code ? Help me thankyou
– nageen nawaz
Nov 21 '18 at 0:09
I didnot get you. Can you please be specific with code ? Help me thankyou
– nageen nawaz
Nov 21 '18 at 0:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400001%2fcannot-read-property-from-of-undefined-at-user-code-index-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown