Currently, I am in the process of working on a project where I aim to provide users with a daily percentage of points based on their current available points and update this data in my Firebase database. My goal is to add points for users on a day-to-day basis using Firebase functions.
I have researched several tutorials on how to set up Firebase Functions; however, I am currently uncertain about how to go about updating the data effectively.
https://i.sstatic.net/uk32N.png
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp;
export const helloWorld = functions.https.onRequest(async(request, response) => {
await updatePoints();
response.send("Hello from Firebase!")
});
export async function updatePoints(){
try{
const db = admin.database();
const ref = db.ref("Users/{userId}")
await ref.update({
"points": "3000"
});
}
catch(err){
console.log("An error occurred: "+err)
}
}