full app
This commit is contained in:
@@ -3,8 +3,12 @@ const NotificationModel = require('../../../models/NotificationModel')
|
||||
const UserModel = require('../../../models/UserModel')
|
||||
const jMoment = require('moment-jalaali')
|
||||
const { sendPushToTokens } = require('../../../utils/pushNotification')
|
||||
const { buildStorageUrl } = require('../../../utils/storageUrl')
|
||||
|
||||
/** ارسال اعلان همگانی — مثل ارسال پیامک، به همهی کاربران */
|
||||
/** ارسال اعلان همگانی — مثل ارسال پیامک، به همهی کاربران. بنر اختیاریه (multer:
|
||||
* routes/panel/notifications/index.js) — هم توی خودِ پوشِ FCM (notification.image،
|
||||
* از قبل توی utils/pushNotification.js پشتیبانی میشد) و هم توی ردیفِ دیتابیسِ هر
|
||||
* کاربر (برای لیستِ داخلِ اپ) ذخیره میشه */
|
||||
const createBroadcast = async (req, res, next) => {
|
||||
try {
|
||||
const { title, body } = req.body
|
||||
@@ -12,11 +16,14 @@ const createBroadcast = async (req, res, next) => {
|
||||
return res.status(400).json({ message: 'عنوان و متن اعلان الزامی است' })
|
||||
}
|
||||
|
||||
const image = req.file ? buildStorageUrl(`/broadcasts/${req.file.filename}`) : null
|
||||
|
||||
const users = await UserModel.find({}).select('_id fcm_tokens fcm_web_tokens').lean()
|
||||
|
||||
const broadcast = await AdminBroadcastModel.create({
|
||||
title,
|
||||
body,
|
||||
image,
|
||||
recipientCount: users.length,
|
||||
sentBy: req.admin?._id
|
||||
})
|
||||
@@ -28,6 +35,7 @@ const createBroadcast = async (req, res, next) => {
|
||||
type: 'admin_broadcast',
|
||||
title,
|
||||
description: body,
|
||||
image,
|
||||
broadcast_id: broadcast._id
|
||||
}))
|
||||
)
|
||||
@@ -39,7 +47,8 @@ const createBroadcast = async (req, res, next) => {
|
||||
title,
|
||||
description: body,
|
||||
type: 'admin_broadcast',
|
||||
data: { broadcastId: String(broadcast._id) }
|
||||
data: { broadcastId: String(broadcast._id) },
|
||||
image
|
||||
}).catch((err) => console.error('[notificationsController] ارسال پوش همگانی خطا:', err.message))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user