full app
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
const NotificationModel = require("../models/NotificationModel");
|
||||
const UserModel = require("../models/UserModel");
|
||||
const { notifyUser } = require("./notifyUser");
|
||||
const { buildStorageUrl } = require("./storageUrl");
|
||||
|
||||
const PURCHASE_TITLE = "پکیج شما خریداری شد";
|
||||
const PURCHASE_DESCRIPTION = "یک کاربر پکیج آموزشی شما را خریداری کرد";
|
||||
const PURCHASE_DESCRIPTION = "دورهی آموزشی شما را خریداری کرد";
|
||||
|
||||
// همون الگوی tagNotification.js/notifyFollowers.js — چون این تابع مستقیم از کنترلر
|
||||
// صدا زده میشه (نه یه جاب زمانبندیشده)، io از index.js با همین setIo تزریق میشه
|
||||
let ioInstance = null;
|
||||
function setIo(io) {
|
||||
ioInstance = io;
|
||||
}
|
||||
|
||||
const createCoursePurchaseNotification = async ({
|
||||
ownerId,
|
||||
@@ -12,12 +20,19 @@ const createCoursePurchaseNotification = async ({
|
||||
if (!ownerId || !buyerId || !courseId) return;
|
||||
if (String(ownerId) === String(buyerId)) return;
|
||||
|
||||
await NotificationModel.create({
|
||||
user_id: ownerId,
|
||||
project_post_id: courseId,
|
||||
const buyer = await UserModel.findById(buyerId).select(
|
||||
"user_name profile_image"
|
||||
);
|
||||
const buyerUsername = buyer?.user_name || "کاربر";
|
||||
const buyerImage = buildStorageUrl(buyer?.profile_image) || undefined;
|
||||
|
||||
await notifyUser(ioInstance, ownerId, {
|
||||
type: "academy_purchase",
|
||||
title: PURCHASE_TITLE,
|
||||
title: buyerUsername,
|
||||
description: PURCHASE_DESCRIPTION,
|
||||
project_post_id: courseId,
|
||||
actor_id: buyerId,
|
||||
image: buyerImage,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error creating course purchase notification:", error);
|
||||
@@ -26,4 +41,5 @@ const createCoursePurchaseNotification = async ({
|
||||
|
||||
module.exports = {
|
||||
createCoursePurchaseNotification,
|
||||
setIo,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user