full app
This commit is contained in:
49
utils/shareableLinkDisplay.js
Normal file
49
utils/shareableLinkDisplay.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const CourseModel = require('../models/CourseModel')
|
||||
const ProjectModel = require('../models/ProjectModel')
|
||||
const AdvertisingModel = require('../models/AdvertisingModel')
|
||||
const ShopModel = require('../models/ShopModel')
|
||||
const ShopProductListingModel = require('../models/ShopProductListingModel')
|
||||
const BookingConfigModel = require('../models/BookingConfigModel')
|
||||
const { PUBLIC_COURSE_STATUSES, PUBLIC_BILLBOARD_STATUSES, PUBLIC_PROJECT_STATUSES } = require('./moderationStatus')
|
||||
|
||||
// عینِ resolveLinkedEntity.js ولی بهجای اعتبارسنجیِ مالکیت، فقط عنوان/عکسِ نمایشی رو
|
||||
// برمیگردونه — برای وقتی که بلاگر داره لینکهای اشتراکیِ یه کاربرِ دیگه (نه خودش) رو میبینه
|
||||
async function resolveShareableLinkDisplay (kind, id) {
|
||||
switch (kind) {
|
||||
case 'pkg': {
|
||||
const course = await CourseModel.findById(id).select('cuorse_name course_image status').lean()
|
||||
if (!course || !PUBLIC_COURSE_STATUSES.includes(course.status)) return null
|
||||
return { title: course.cuorse_name || 'پکیج آموزشی', image: course.course_image || null }
|
||||
}
|
||||
case 'project': {
|
||||
const project = await ProjectModel.findById(id).select('title status').lean()
|
||||
if (!project || !PUBLIC_PROJECT_STATUSES.includes(project.status)) return null
|
||||
return { title: project.title || 'پروژه', image: null }
|
||||
}
|
||||
case 'billboard': {
|
||||
const ad = await AdvertisingModel.findById(id).select('title images status').lean()
|
||||
if (!ad || !PUBLIC_BILLBOARD_STATUSES.includes(ad.status)) return null
|
||||
return { title: ad.title || 'بیلبورد', image: ad.images?.[0] || null }
|
||||
}
|
||||
case 'shop': {
|
||||
const shop = await ShopModel.findById(id).select('name logo status').lean()
|
||||
if (!shop || !['active', 'pending_review'].includes(shop.status)) return null
|
||||
return { title: shop.name, image: shop.logo || null }
|
||||
}
|
||||
case 'shopproduct': {
|
||||
const listing = await ShopProductListingModel.findById(id).select('title images primaryImageIndex status').lean()
|
||||
if (!listing || !['active', 'pending_shop_approval'].includes(listing.status)) return null
|
||||
const image = listing.images?.[listing.primaryImageIndex ?? 0] ?? listing.images?.[0] ?? null
|
||||
return { title: listing.title, image }
|
||||
}
|
||||
case 'booking': {
|
||||
const config = await BookingConfigModel.findOne({ owner: id, status: 'active' }).select('name').lean()
|
||||
if (!config) return null
|
||||
return { title: config.name || 'رزرو نوبت', image: null }
|
||||
}
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { resolveShareableLinkDisplay }
|
||||
Reference in New Issue
Block a user