Initial commit
This commit is contained in:
@@ -14,6 +14,11 @@ const AdvertisingLikeModel = require('../../../models/AdvertisingLikeModel')
|
||||
const AdvertisingComment = require('../../../models/AdvertisingCommentModel')
|
||||
const AdvertisingRatingModel = require('../../../models/AdvertisingRatingModel')
|
||||
const AdvertisingProfileModel = require('../../../models/AdvertisingProfile')
|
||||
const { createLikeNotification } = require('../../../utils/likeNotification')
|
||||
const {
|
||||
createCommentNotification,
|
||||
createRatingNotification
|
||||
} = require('../../../utils/commentNotification')
|
||||
|
||||
const createAdvertisingValidationRules = () => {
|
||||
return [
|
||||
@@ -698,6 +703,14 @@ const toggleLike = async (req, res, next) => {
|
||||
// افزایش تعداد لایکها در تبلیغات
|
||||
advertising.likesCount += 1
|
||||
await advertising.save()
|
||||
|
||||
await createLikeNotification({
|
||||
ownerId: advertising.creator_id,
|
||||
likerId: userId,
|
||||
entityId: advertising._id,
|
||||
type: 'billboard_like'
|
||||
})
|
||||
|
||||
return res.status(201).json({ message: 'ویترین با موفقیت لایک شد' })
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -727,8 +740,16 @@ const addComment = async (req, res, next) => {
|
||||
})
|
||||
|
||||
await newComment.save()
|
||||
// افزایش تعداد کامنتهای تبلیغ
|
||||
// await AdvertisingModel.findByIdAndUpdate(advertisingId, { $inc: { commentsCount: 1 } })
|
||||
|
||||
const advertising = await AdvertisingModel.findById(advertisingId)
|
||||
if (advertising) {
|
||||
await createCommentNotification({
|
||||
ownerId: advertising.creator_id,
|
||||
commenterId: userId,
|
||||
entityId: advertising._id,
|
||||
type: 'billboard_comment'
|
||||
})
|
||||
}
|
||||
|
||||
res.status(201).json({ message: 'کامنت با موفقیت اضافه شد', comment: newComment })
|
||||
} catch (error) {
|
||||
@@ -783,6 +804,13 @@ const rateAdvertising = async (req, res, next) => {
|
||||
rating
|
||||
})
|
||||
await newRating.save()
|
||||
|
||||
await createRatingNotification({
|
||||
ownerId: advertising.creator_id,
|
||||
raterId: userId,
|
||||
entityId: advertising._id,
|
||||
type: 'billboard_rating'
|
||||
})
|
||||
}
|
||||
|
||||
// بهروزرسانی امتیازات کلی کاربر
|
||||
|
||||
Reference in New Issue
Block a user