I'm just learning how to use Firebase cloud functions written in typescript. I want to set up a cron-job to ping my function every day. And I want the function to iterate through every node in the 'users' node and push the dailyTimeObject to each 'user' node. But what I can't figure out, is if there is a user id wild card I can use to write past the user ids. As you can see I tried {uid} but that just created a new node.
This is my function:
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
admin.initializeApp()
export const dailyShiftPush = functions.https.onRequest((request, response) => {
const pushRef = admin.database().ref('/users/{uid}/dailyTimeObject').push();
const pushKey = pushRef.key
const currentTime = Date.now()
const dailyTimeObject = {
"time": currentTime,
"entryId": pushKey
}
return pushRef.set(dailyTimeObject)
});
And this is what my firebase realtime database json tree looks like. And I want the {uid} node to be under the actual user id.
{
"users" : {
"zVfojjhYUqOzM7hfm2ff8yQtozq2" : {
"clockIn" : {
"-LQRpr7wrDAn0kcuicnz" : {
"clockInTime" : 1541303401051,
"entryId" : "-LQRpr7wrDAn0kcuicnz"
},
"-LQU-_MY8z81yJyUkNJ3" : {
"clockInTime" : 1541339764229,
"entryId" : "-LQU-_MY8z81yJyUkNJ3"
}
},
"clockOut" : {
"-LQRprt3OI465av7sOsF" : {
"clockOutTime" : 1541303404130,
"entryId" : "-LQRprt3OI465av7sOsF"
}
}
},
"{uid}" : {
"dailyTimeObject" : {
"-LQW1a1w_P0WaYiZevle" : {
"entryId" : "-LQW1a1w_P0WaYiZevle",
"time" : 1541373845702
}
}
}
}
}
Thanks in advance!