Add full project files

This commit is contained in:
root
2026-07-04 19:24:56 +03:30
parent d54f5441a3
commit b245e7b71a
835 changed files with 30149 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
const cron = require('node-cron')
const AdvertisingModel = require('../models/AdvertisingModel')
const NotificationModel = require('../models/NotificationModel')
// تابع برای به‌روزرسانی تبلیغات منقضی شده
const updateExpiredAdvertisings = async () => {
const now = new Date()
const oneMonthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000)
try {
const expiredAds = await AdvertisingModel.find({
status: 'accepted',
acceptedAt: { $lte: oneMonthAgo }
})
for (const ad of expiredAds) {
ad.status = 'expired'
ad.payment_status = null
await ad.save()
// ایجاد و ذخیره نوتیفیکیشن
const notification = new NotificationModel({
user_id: ad.creator_id,
project_post_id: ad._id,
type: 'vitrine',
title: 'انقضای ویترین',
description: `ویترین شما با عنوان: ${ad.title} منقضی شد `
})
await notification.save()
}
console.log(`Updated ${expiredAds.length} expired advertisings successfully`)
} catch (error) {
console.error('Error updating expired advertisings:', error)
}
}
// تنظیم کرون جاب برای اجرای هر ساعت
cron.schedule('0 * * * *', () => {
console.log('Running cron job to update expired advertisings')
updateExpiredAdvertisings()
})
module.exports = updateExpiredAdvertisings

44
services/ProjectCron.js Normal file
View File

@@ -0,0 +1,44 @@
const cron = require('node-cron')
const ProjectModel = require('../models/ProjectModel')
const NotificationModel = require('../models/NotificationModel')
// تابع برای به‌روزرسانی پروژه‌های منقضی شده
const updateExpiredProjects = async () => {
const now = new Date()
const oneMonthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000)
try {
// جستجوی پروژه‌های منقضی شده که هنوز به‌روزرسانی نشده‌اند
const expiredProjects = await ProjectModel.find({
isExpired: false, // فقط پروژه‌هایی که هنوز منقضی نشده‌اند
acceptedAt: { $lte: oneMonthAgo } // بر اساس تاریخ انقضا
})
for (const project of expiredProjects) {
project.isExpired = true // تنظیم وضعیت منقضی شده
await project.save()
// ایجاد و ذخیره نوتیفیکیشن
const notification = new NotificationModel({
user_id: project.creator_id,
project_post_id: project._id,
type: 'project',
title: 'انقضای پروژه',
description: `پروژه شما با عنوان: ${project.title} منقضی شد.`
})
await notification.save()
}
console.log(`Updated ${expiredProjects.length} expired projects successfully`)
} catch (error) {
console.error('Error updating expired projects:', error)
}
}
// تنظیم کرون جاب برای اجرای هر ساعت
cron.schedule('0 * * * *', () => {
console.log('Running cron job to update expired projects')
updateExpiredProjects()
})
module.exports = updateExpiredProjects

13
services/TokenService.js Normal file
View File

@@ -0,0 +1,13 @@
const jwt = require('jsonwebtoken')
exports.sign = (data) => {
return jwt.sign(data, process.env.APP_SECRET)
}
exports.verify = (token) => {
try {
jwt.verify(token, process.env.APP_SECRET)
return true
} catch (error) {
return false
}
}