Files
modstagram-back/utils/commentNotification.js
root c62e4c0577 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
2026-07-11 14:06:46 +03:30

58 lines
1.5 KiB
JavaScript

const NotificationModel = require('../models/NotificationModel')
const { resolveCourseOwnerId } = require('./likeNotification')
const COMMENT_TITLE = 'یک کامنت برای شما ثبت شد'
const COMMENT_DESCRIPTION = 'یک کامنت برای شما ثبت شد'
const RATING_TITLE = 'یک امتیاز برای شما ثبت شد'
const RATING_DESCRIPTION = 'یک امتیاز برای شما ثبت شد'
const createCommentNotification = async ({
ownerId,
commenterId,
entityId,
type = 'post_comment'
}) => {
try {
if (!ownerId || !commenterId || !entityId) return
if (String(ownerId) === String(commenterId)) return
await NotificationModel.create({
user_id: ownerId,
project_post_id: entityId,
type,
title: COMMENT_TITLE,
description: COMMENT_DESCRIPTION
})
} catch (error) {
console.error('Error creating comment notification:', error)
}
}
const createRatingNotification = async ({
ownerId,
raterId,
entityId,
type = 'billboard_rating'
}) => {
try {
if (!ownerId || !raterId || !entityId) return
if (String(ownerId) === String(raterId)) return
await NotificationModel.create({
user_id: ownerId,
project_post_id: entityId,
type,
title: RATING_TITLE,
description: RATING_DESCRIPTION
})
} catch (error) {
console.error('Error creating rating notification:', error)
}
}
module.exports = {
createCommentNotification,
createRatingNotification,
resolveCourseOwnerId
}