I know the answer must be silly for you but I have just started javascript to do functions with firebase and I block on my script even after reading several questions with the same problem here (stackoverflow).
When running my script tells me:
TypeError: d.getFullYear is not a function
at Date.sameDay (/user_code/index.js:36:41)
at /user_code/index.js:61:33
at process._tickDomainCallback (internal/process/next_tick.js:129:7)
"
exports.sendNotificationToNewUser = functions.https.onRequest((request, response) => {
// Enable logging
// admin.database.enableLogging(true);
Date.prototype.sameDay = function(d) {
return this.getFullYear() === d.getFullYear()
&& this.getDate() === d.getDate()
&& this.getMonth() === d.getMonth();
}
// Loop through users in order with the forEach() method. The callback
// provided to forEach() will be called synchronously with a DataSnapshot
// for each child:
var query = admin.database().ref("users").orderByKey();
var defaultAuth = admin.auth();
query.once("value")
.then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
// user will be "ada" the first time and "alan" the second time
var user_id = childSnapshot.key;
// childData will be the actual contents of the child
var user_data = childSnapshot.val();
console.log(user_id);
admin.auth().getUser(user_id)
.then(function(userRecord) {
var create_date = userRecord.metadata.createdAt
console.log("Creation date:", create_date);
create_date.setDate(create_date.getDate()+4);
if (create_date.sameDay(Date.now())) {
//things
}
});
});
});
response.send("OK");
})