In my Cloud Firestore database, always a user is registered, the database stores the time the event occurs:
const p = usersReference.add({
...,
registerTime: admin.firestore.FieldValue.serverTimestamp(),
...
});
My goal is to create another cloud function that gets a user as input and returns if there is at least 5 days since the user was registered:
export const get_user_timeleft = functions.https.onRequest((request, response) => {
//useless part of the function...
querySnapshot.forEach(function (documentSnapshot) {
//Here I know that documentSnapshot.data().registerTime
//returns whatever is saved in the database.
//How can I return true or false if there's been 5
//or more days since the user registered?
response.json(TRUE of FALSE);
})
}
})
.catch(function(error) {
response.json(error);
});
});
Clearly I can call admin.firestore.FieldValue.serverTimestamp()
again and try to subtract them, but I don't even know the type it is. In the past I've managed to use is as a Date
, but since Firebase is saying that Date
will be deprecated, I don't know how to deal with it.