This commit is contained in:
payacom
2026-09-24 21:03:27 +03:30
parent 7f0ddfde70
commit 806471241e
43 changed files with 2166 additions and 144 deletions

View File

@@ -6,6 +6,7 @@ const RequestModel = require('../../../models/RequestModel')
const UserModel = require('../../../models/UserModel')
const jwt = require('jsonwebtoken')
const { buildUnifiedInterestScore, blendFreshIntoRanked } = require('../../../utils/exploreAlgorithm')
const { findActiveAd, buildAdProjectItem, trackAdEvent } = require('../../../utils/adDelivery')
function getOptionalUserId (req) {
try {
@@ -168,6 +169,27 @@ const getProjects = async (req, res, next) => {
} catch {
/* non-blocking: personalization is a bonus, never break the listing */
}
// تبلیغِ نوع project — عینِ الگوی first_post (adDelivery.js): فقط صفحه‌ی اول،
// فقط برای کاربرِ واردشده، خطاش هیچ‌وقت نباید لیستِ پروژه‌ها رو بشکنه
try {
const userId = getOptionalUserId(req)
if (userId) {
const viewer = await UserModel.findById(userId)
.select('country province city gender expertise sub_expertise')
.lean()
const ad = await findActiveAd('project', { ...viewer, _id: userId })
if (ad) {
const adProject = await buildAdProjectItem(ad)
if (adProject) {
newProj = [adProject, ...newProj]
trackAdEvent(ad._id, 'view').catch(() => {})
}
}
}
} catch (adError) {
console.error('project ad injection error:', adError.message)
}
}
res.status(200).json({