I am trying to send push notification to the users and trying to send 3 times or 2 times a day but after that i don't want to send the notification like i have sent 3 notification today and don't want to send notification after that and next cycle starts from next day and so on I am unable to stop after the 7pm i wanted to stop the node cron after 7 pm and start the cycle next day.
const cron = require("node-cron");
const { db, growthfile20724db } = require("../constant");
let AWS = require("aws-sdk");
// const { getAuth } = require('../utils/reportUtils');
AWS.config.update({
accessKeyId: "",
secretAccessKey: "",
region: "us-east-1",
});
const sns = new AWS.SNS();
const sendReminderRet = async (profile) => {
console.log(profile);
const updateSnapshot = await db
.collection("Updates")
.where("phoneNumber", "==", profile.phoneNumber)
.get();
const updateArray = updateSnapshot.docs.map(
(doc) => doc.data().registrationToken
);
console.log("registerToken", updateArray[0]);
cron.schedule("* * /3 * * *", () => {
console.log("running a task every ten minutes");
let params = {
PlatformApplicationArn: "",
Token: `${updateArray[0]}`,
};
let payload2 = JSON.stringify({
default: "push notification",
GCM: JSON.stringify({
notification: {
body: "Hi ",
title: "Reminder",
},
// data: {
// testdata: "Check out these awesome deals!",
// url: "www.amazon.com",
// },
}),
});
sns.createPlatformEndpoint(params, (err, data) => {
if (err) {
console.log(err);
} else {
sns.publish(
{
Message: payload2, // Required
MessageStructure: "json",
TargetArn: data.EndpointArn,
},
(err, data) => {
if (err) {
console.log(err.stack);
} else {
console.log(data);
}
}
);
}
});
});
};
module.exports = { sendReminderRet };