UnknownSec Bypass
403
:
/
var
/
www
/
stp-bhaktisagar-backend
/
src
/
helpers
/ [
drwxrwxr-x
]
Menu
Upload
Mass depes
Mass delete
Terminal
Info server
About
name :
eventSchedule.helper.js
let jobs = {}; const moment = require("moment"); const schedule = require("node-schedule"); const { sendPushNotification, AndroidStyle } = require("../util/firebase"); const commonModel = require("../models/common.model"); const sendEventNotification = (event) => { sendPushNotification({ topic: "public", title: event.notification_title, body: event.description, data: { event: event, }, options: { android: { // largeIcon: 'logo', ...(event.image ? { style: { type: AndroidStyle.BIGPICTURE, picture: event.image, // picture: "https://stp.santgyaneshwarji.org/thumb/6.jpg", // summary: "kk="+event.description, }, } : {}), }, }, }); }; const cancelEventNotificationJobs = (id) => { if (jobs[id]) { jobs[id].forEach((j) => { console.log(j?.cancel); j?.cancel(); }); delete jobs[id]; } }; const addEventNotificationJobs = (event) => { let { id, start_datetime, end_datetime } = event; let start = moment(start_datetime); let end = moment(end_datetime); let _s = start.clone(); let jobDates = [_s.clone().subtract(1, "day")]; while (1) { if (_s.isBefore(end)) { jobDates = [...jobDates, _s.clone().subtract(20, "minute"), _s.clone()]; } else { break; } _s.add(1, "day"); } cancelEventNotificationJobs(id); let jobSc = jobDates.map((jd) => { // let job = jd.toDate(); let job = schedule.scheduleJob(jd.toDate(), function () { sendEventNotification(event); console.log(jd.format("YYYY-MM-DD hh:mm:ss A"), "event job run"); }); return job; }); jobs[id] = jobSc; console.log( // id, // diff.asDays(), start.format("YYYY-MM-DD HH:mm:ss"), end.format("YYYY-MM-DD HH:mm:ss"), // isSameDay, jobDates.map((r) => r.format("YYYY-MM-DD HH:mm:ss")) // jobs ); }; const scheduleEventNotificationJobs = async () => { let results = await commonModel.getAll("events", "*", "order by id desc"); results = results.filter((r) => { let today = moment(); return ( moment(r.start_datetime).isSameOrAfter(today) || moment(r.end_datetime).isSameOrAfter(today) ); }); results.forEach((ev) => { addEventNotificationJobs(ev); }); // console.log(results); }; exports.addEventNotificationJobs = addEventNotificationJobs; exports.sendEventNotification = sendEventNotification; exports.cancelEventNotificationJobs = cancelEventNotificationJobs; exports.scheduleEventNotificationJobs = scheduleEventNotificationJobs; // addEventNotificationJobs({ // title: "dssd", // description: "sddsdsds", // notification_title: "dsdsds", // visible: 1, // //image: "http://192.168.115.128:4000/images/abstract-background-18-1699093140569.jpg", // created_at: "2023-11-21T10:57:22.000Z", // start_datetime: moment().add(30, "second").toDate(), // end_datetime: moment().add(2, "day").add(4, "hour").toDate(), // }); // this.addEventNotificationJobs({ // title: "कल्की अवतार भगवान सदानन्द जी की अमृत वाणी -", // description: "5 st Date of every month,Kalki Avtar Prachar Dham Ashram,Karitoran , Lalitpur U.P. INDIA", // notification_title: "कल्की अवतार भगवान सदानन्द जी की अमृत वाणी -", // visible: 1, // image: // "http://192.168.115.128:4000/images/abstract-background-18-1699093140569.jpg", // created_at: "2023-11-21T10:57:22.000Z", // start_datetime: moment().add(55, "second").toDate(), // end_datetime: moment().add(2, "day").add(4, "hour").toDate(), // });
Copyright © 2025 - UnknownSec