'use-strict'
const functions = require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.pushNotification=functions.firestore.
document("Users/{user_id}/Notification/{notification_Id}").onWrite((change,
context)=> {
const user_id=context.params.user_id;
const notification_Id=context.params.notification_Id;
return admin.firestore().collection("Users").doc(user_id)
.collection("Notification").doc(notification_id).get().then(queryResult => {
const from_user_id=queryResult.data().from;
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_email=result[0].data().email;
const to_email=result[1].data().email;
console.log("from " + from_email + " to " + to_email);
});
});
});
它有1条警告和1条错误。
警告是避免嵌套承诺。
错误是(然后每个错误都应返回值或抛出诺言/始终返回)..........