Send SMS after 3 days to user for register sim card
This commit is contained in:
Mr Swift
2024-10-04 13:43:09 +03:30
parent e8c1ab00f2
commit 4dc6000976
4 changed files with 62 additions and 0 deletions
+34
View File
@@ -1,5 +1,6 @@
/* eslint-disable no-unused-vars */
const User = require('../models/User')
const InstalledDevice = require('../models/GPS.InstalledDevice')
const Lottery = require('../models/Lottery')
const SurveyCheck = require('../models/SurveyCheck')
const Survey = require('../models/Survey')
@@ -8,6 +9,8 @@ const { saveUserToArpa, updateUserOnArpa } = require('../ArpaWebservice')
const { generateRandomDigitsInRangeOf } = require('./controllersHelperFunctions')
const { SMS } = require('./SMS_Module')
const { phrases } = require('./SMS_Phrases')
// eslint-disable-next-line import/order
const Cron = require("cron").CronJob;
/// /////// times
const minute = 1000 * 60
@@ -15,6 +18,35 @@ const hour = minute * 60
const day = hour * 24
/// /////// jobs
const job = new Cron("0 0 * * *", async () => {
console.log('✅ --job: check devices for activation is running')
try {
const devices = await InstalledDevice.find({
$or: [
{ status: 0 },
{ status: 2 }
]
}).populate('userId', 'mobile_number').populate('deviceId', 'model')
for await (const device of devices) {
// item time and timeout
const itemTime = Date.parse(device.created_at)
const timeout = itemTime + (day * 3)
if (Date.now() >= timeout && !device.check) {
device.check = true;
await device.save()
SMS([device.userId.mobile_number], `کاربر گرامی\n \n \nجهت ثبت سیمکارت برای دستگاه ${device.deviceId.model} \nبا شناسه : ${device.IMEI} \nلطفا زود تر اقدام کنید `)
}
}
} catch (e) {
console.log(e)
}
})
const jobs = {
checkUserActivation() {
console.log('✅ --job: check users for activation is running')
@@ -277,6 +309,8 @@ const devTools = {
}
module.exports = () => {
job.start()
jobs.checkDeviceActivation()
jobs.checkUserActivation()
jobs.drawLottery()
jobs.checkIfAnnouncementsExpired()