我正在尝试在Typescript中创建一个Cloud Function来监听节点更改,然后获取所有“预订”,获取客户价值并获取“通知”节点中的所有相应令牌,我将用于发送通知。以下是我到目前为止的情况。这是我迷失的一团糟。
async function getBookings(){
admin.database().ref("bookings") //how do i loop through all booking and return?
}
export const sendNotificationLatenessNew = functions.database.ref("bookings/{pushId}/checkOutTime")
.onWrite(event => {
//get all 'bookings' where cancelled is false
//use the customer field get all user id (customer)
//loop through 'notifications' using the customer value to get tokens
var payload = {
data:{
username: "test",
email:"dsfsgd@fdf.com"
}
};
return admin.messaging().sendToDevice("e-pXqGoQRpk:APA91bEZJAuDSFfOmTZhBWCIDOGaEYIk2_bdAHaHKK9Yr7-iS7H34sj1YRxVpuSChAKQJ4q667zVf-0yNGGla7f7F1XNHU0ESZjxFfJIAIh_gqkybF2dY4eJQwlYqNJLamaLAfnyVSbj", payload)
.then(function(response){
console.log("success late sending message, " , response);
}).catch(function(error){
console.log("error late sending message, " , error);
});
});