From 66ff1b892f26e7108f556ad576bd3f945633a40b Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 13 Sep 2024 09:41:44 +0300 Subject: [PATCH] set cron for app update --- routes/processes/nishauri_new.js | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/routes/processes/nishauri_new.js b/routes/processes/nishauri_new.js index fc3b963..77ccf5d 100644 --- a/routes/processes/nishauri_new.js +++ b/routes/processes/nishauri_new.js @@ -5522,5 +5522,52 @@ router.delete( } ); +const sendAppUpdateNotification = (registrationToken) => { + if (!registrationToken) { + return; + } + + const message = { + notification: { + title: "Nishauri Update Available!", + body: "New features and improvements are here! Update your app now for a better experience." + }, + token: registrationToken + }; + + messaging + .send(message) + .then((response) => { + //console.log("Successfully sent app update notification:", response); + }) + .catch((error) => { + //console.error("Error sending app update notification:", error); + }); +}; + +const notifyUsersAboutAppUpdate = async () => { + try { + + let users = await NUsers.findAll({ + attributes: ['id', 'fcm_token'] + }); + + for (const user of users) { + const registrationToken = user.fcm_token; + sendAppUpdateNotification(registrationToken); + } + } catch (error) { + //console.error("Error:", error.message); + } +}; + +// Schedule the notification +const specificDateAndTime = '30 9 14 9 *'; // September 14, 9:30 AM + +cron.schedule(specificDateAndTime, () => { + notifyUsersAboutAppUpdate(); +}); + + module.exports = router; //module.exports = { router, users };