- Added dotenv configuration for environment variables - Fixed MongoDB connection string loading - Configured server port to 3005 - Updated cron jobs for expired messages
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
const NotificationModel = require('../models/NotificationModel')
|
|
const AcademyModel = require('../models/AcademyModel')
|
|
|
|
const LIKE_TITLE = 'پست شما لایک شد'
|
|
const LIKE_DESCRIPTION = 'پست شما لایک شد'
|
|
|
|
const createLikeNotification = async ({
|
|
ownerId,
|
|
likerId,
|
|
entityId,
|
|
type = 'post_like'
|
|
}) => {
|
|
try {
|
|
if (!ownerId || !likerId || !entityId) return
|
|
if (String(ownerId) === String(likerId)) return
|
|
|
|
await NotificationModel.create({
|
|
user_id: ownerId,
|
|
project_post_id: entityId,
|
|
type,
|
|
title: LIKE_TITLE,
|
|
description: LIKE_DESCRIPTION
|
|
})
|
|
} catch (error) {
|
|
console.error('Error creating like notification:', error)
|
|
}
|
|
}
|
|
|
|
const resolveCourseOwnerId = async (course) => {
|
|
if (course?.user_id) {
|
|
return course.user_id
|
|
}
|
|
|
|
if (course?.academyId) {
|
|
const academy = await AcademyModel.findById(course.academyId)
|
|
if (academy?.userId) {
|
|
return academy.userId
|
|
}
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
module.exports = {
|
|
createLikeNotification,
|
|
resolveCourseOwnerId
|
|
}
|