Files
modstagram-back/utils/academyNotification.js
payacom 3f416a7a60 full
2026-08-31 20:45:41 +03:30

30 lines
803 B
JavaScript

const NotificationModel = require("../models/NotificationModel");
const PURCHASE_TITLE = "پکیج شما خریداری شد";
const PURCHASE_DESCRIPTION = "یک کاربر پکیج آموزشی شما را خریداری کرد";
const createCoursePurchaseNotification = async ({
ownerId,
buyerId,
courseId,
}) => {
try {
if (!ownerId || !buyerId || !courseId) return;
if (String(ownerId) === String(buyerId)) return;
await NotificationModel.create({
user_id: ownerId,
project_post_id: courseId,
type: "academy_purchase",
title: PURCHASE_TITLE,
description: PURCHASE_DESCRIPTION,
});
} catch (error) {
console.error("Error creating course purchase notification:", error);
}
};
module.exports = {
createCoursePurchaseNotification,
};