-1

Im currently working on a project and I want to give percentage of points to every users daily based on their current points available and update the user data in my firebase database. I wanted to add points for my users on a daily basis using firebase functions.

I've looked up several guides on setting up Firebase Functions and right now I'm just not sure how can i update the data.

User Database

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("Error occured:"+err)
    }
}
Philip Teng
  • 67
  • 1
  • 7

1 Answers1

0

The project sounds pretty clear to me. It should be a three step process like this to implement it:

  1. create a Cloud Functions that runs every day,

  2. loop over the data in your database,

  3. update the property

If you get stuck on a specific step along the way, post a question with the minimal complete/standalone code that reproduces where you are stuck.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Hi there, I've attempt to update the points to test out the functions and apparently it does not changes anything – Philip Teng Jul 10 '19 at 09:18