fix: resolve MongoDB connection and port configuration issues

- Added dotenv configuration for environment variables
- Fixed MongoDB connection string loading
- Configured server port to 3005
- Updated cron jobs for expired messages
This commit is contained in:
root
2026-07-11 14:06:46 +03:30
parent 51eb7d0224
commit c62e4c0577
175 changed files with 23463 additions and 21573 deletions

View File

@@ -1,68 +1,68 @@
const jwt = require('jsonwebtoken')
const NotificationModel = require('../../../models/NotificationModel')
const jMoment = require('moment-jalaali')
const getNotifications = async (req, res, next) => {
try {
const token = req.header('Authorization').split(' ')[1]
if (!token) return res.status(401).send('Access Denied')
const decodedToken = jwt.verify(token, process.env.APP_SECRET)
const userId = decodedToken.id
const { page = 1, limit = 10, search } = req.query // افزودن پارامترهای صفحه‌بندی به درخواست
const filter = { user_id: userId }
if (search) {
filter.$or = [
{ title: { $regex: search, $options: 'i' } },
{ description: { $regex: search, $options: 'i' } }
]
}
// استفاده از مدل پیجینیت شده برای دریافت نتایج صفحه‌بندی شده
const options = {
page: parseInt(page), // تبدیل صفحه به عدد صحیح
limit: parseInt(limit), // تبدیل محدودیت به عدد صحیح
sort: { createdAt: -1 } // بر اساس زمان ایجاد (createdAt) مرتب کنید (نزولی)
}
// دریافت اعلان‌های مربوط به کاربر با استفاده از userId
let notifications = await NotificationModel.paginate(filter, options)
const totalPages = notifications.totalPages
const totalItems = notifications.totalDocs
notifications = notifications?.docs.map(notification => {
const jDate = jMoment(notification.createdAt).format('jYYYY-jMM-jDD HH:mm')
return {
...notification._doc,
createdAt: jDate
}
})
// تغییر وضعیت "read" اعلان‌ها به "true"
await NotificationModel.updateMany({ user_id: userId }, { read: true })
res.json({
notifications,
totalPages, // ارسال تعداد کل صفحات
totalItems // ارسال تعداد کل آیتم‌ها
})
} catch (error) {
next(error)
}
}
const unreadNotifications = async (req, res, next) => {
try {
const token = req.header('Authorization').split(' ')[1]
if (!token) return res.status(401).send('Access Denied')
const decodedToken = jwt.verify(token, process.env.APP_SECRET)
const userId = decodedToken.id
// دریافت تعداد اعلان‌های جدید برای کاربر
const newNotificationsCount = await NotificationModel.countDocuments({ user_id: userId, read: false }).exec()
res.json({ newNotificationsCount })
} catch (error) {
next(error)
}
}
module.exports = {
getNotifications, unreadNotifications
}
const jwt = require('jsonwebtoken')
const NotificationModel = require('../../../models/NotificationModel')
const jMoment = require('moment-jalaali')
const getNotifications = async (req, res, next) => {
try {
const token = req.header('Authorization').split(' ')[1]
if (!token) return res.status(401).send('Access Denied')
const decodedToken = jwt.verify(token, process.env.APP_SECRET)
const userId = decodedToken.id
const { page = 1, limit = 10, search } = req.query // افزودن پارامترهای صفحه‌بندی به درخواست
const filter = { user_id: userId }
if (search) {
filter.$or = [
{ title: { $regex: search, $options: 'i' } },
{ description: { $regex: search, $options: 'i' } }
]
}
// استفاده از مدل پیجینیت شده برای دریافت نتایج صفحه‌بندی شده
const options = {
page: parseInt(page), // تبدیل صفحه به عدد صحیح
limit: parseInt(limit), // تبدیل محدودیت به عدد صحیح
sort: { createdAt: -1 } // بر اساس زمان ایجاد (createdAt) مرتب کنید (نزولی)
}
// دریافت اعلان‌های مربوط به کاربر با استفاده از userId
let notifications = await NotificationModel.paginate(filter, options)
const totalPages = notifications.totalPages
const totalItems = notifications.totalDocs
notifications = notifications?.docs.map(notification => {
const jDate = jMoment(notification.createdAt).format('jYYYY-jMM-jDD HH:mm')
return {
...notification._doc,
createdAt: jDate
}
})
// تغییر وضعیت "read" اعلان‌ها به "true"
await NotificationModel.updateMany({ user_id: userId }, { read: true })
res.json({
notifications,
totalPages, // ارسال تعداد کل صفحات
totalItems // ارسال تعداد کل آیتم‌ها
})
} catch (error) {
next(error)
}
}
const unreadNotifications = async (req, res, next) => {
try {
const token = req.header('Authorization').split(' ')[1]
if (!token) return res.status(401).send('Access Denied')
const decodedToken = jwt.verify(token, process.env.APP_SECRET)
const userId = decodedToken.id
// دریافت تعداد اعلان‌های جدید برای کاربر
const newNotificationsCount = await NotificationModel.countDocuments({ user_id: userId, read: false }).exec()
res.json({ newNotificationsCount })
} catch (error) {
next(error)
}
}
module.exports = {
getNotifications, unreadNotifications
}