This commit is contained in:
payacom
2026-08-31 20:45:41 +03:30
parent fa9f23c61d
commit 3f416a7a60
367 changed files with 621895 additions and 6443 deletions

36
utils/tagNotification.js Normal file
View File

@@ -0,0 +1,36 @@
const NotificationModel = require('../models/NotificationModel')
const UserModel = require('../models/UserModel')
const createTagNotifications = async ({ taggerId, taggedUserIds, postId }) => {
try {
if (!taggerId || !postId || !taggedUserIds?.length) return
const uniqueIds = [...new Set(taggedUserIds.map(String))].filter(
(id) => id !== String(taggerId)
)
if (!uniqueIds.length) return
const tagger = await UserModel.findById(taggerId).select('user_name')
const taggerUsername = tagger?.user_name || 'کاربر'
const message = `${taggerUsername} شما را در پستی نشانه‌گذاری کرد.`
await Promise.all(
uniqueIds.map((userId) =>
NotificationModel.create({
user_id: userId,
project_post_id: postId,
actor_id: taggerId,
type: 'post_tag',
title: message,
description: message
})
)
)
} catch (error) {
console.error('Error creating tag notifications:', error)
}
}
module.exports = {
createTagNotifications
}