云函数使打字稿中的多个数据库读取

时间:2018-02-05 20:22:25

标签: typescript firebase firebase-realtime-database google-cloud-functions

我正在尝试在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);
    });

});

这是我的数据库 enter image description here

0 个答案:

没有答案