full app
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user