added a function to move daily leaderboards to history

This commit is contained in:
Jack 2020-07-04 00:11:26 +01:00
parent 295d02b70d
commit 650f0c29b1

View file

@ -908,6 +908,36 @@ exports.getLeaderboard = functions.https.onCall((request, response) => {
});
});
exports.scheduledFunctionCrontab = functions.pubsub
.schedule("59 23 * * *")
.timeZone("Europe/London") // Users can choose timezone - default is America/Los_Angeles
.onRun((context) => {
console.log("moving daily leaderboards to history");
admin
.firestore()
.collection("leaderboards")
.where("type", "==", "daily")
.get()
.then((res) => {
res.docs.forEach((doc) => {
let lbdata = doc.data();
t = new Date();
admin
.firestore()
.collection("leaderboards_history")
.doc(`${t.getDate()}_${t.getMonth()}_${t.getFullYear()}`)
.set(lbdata);
admin.firestore().collection("leaderboards").doc(doc.id).set(
{
board: [],
},
{ merge: true }
);
});
});
return null;
});
// exports.getConfig = functions.https.onCall((request,response) => {
// try{
// if(request.uid === undefined){