const mongoose = require('mongoose'); const timestamp = require('mongoose-timestamp'); const mongoosePaginate = require('mongoose-paginate-v2'); const modelSchema = new mongoose.Schema({ post_images: { type: [String], // آرایه‌ای از مسیرهای تصاویر required: false, default: [], }, post_video: { type: String, // مسیر ویدئو required: false, trim: true, default: null, }, type: { type: String, // نوع پست: 'image' یا 'video' required: true, enum: ['image', 'video'], }, files: [ { path: { type: String, required: true }, type: { type: String, enum: ['image', 'video'], required: true }, } ], caption: { type: String, required: false, trim: true, maxLength: 2000, default: null, }, status: { type: String, required: false, trim: true, enum: ['pending', 'temp_accept', 'accept', 'reject'], default: 'pending', }, report_hidden: { type: Boolean, default: false, }, is_archived: { type: Boolean, default: false, }, archived_at: { type: Date, default: null, }, user_id: { type: mongoose.Schema.Types.ObjectId, ref: 'User', }, tagged_users: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User', }], linked_course_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Course', default: null, }, linked_project_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Project', default: null, }, linked_billboard_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Advertising', default: null, }, linked_shop_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Shop', default: null, }, linked_shop_product_id: { type: mongoose.Schema.Types.ObjectId, ref: 'ShopProductListing', default: null, }, // برخلاف بقیه‌ی linked_*_id ها که _id خودِ آیتم لینک‌شده رو نگه می‌دارن، این یکی userId // مالک کانفیگ رزروئه (نه _id خودِ BookingConfig) — چون صفحه‌ی عمومی رزرو با userId // مسیردهی می‌شه (/booking/[userId]) نه شناسه‌ی کانفیگ linked_booking_id: { type: mongoose.Schema.Types.ObjectId, ref: 'User', default: null, }, likes: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User', }], lat: { type: String, trim: true, default: null, }, lng: { type: String, trim: true, default: null, }, country: { type: Object, default: null, }, province: { type: Object, default: null, }, city: { type: Object, default: null, }, comments: { type: Object, default: null, }, }); // getUserPosts/getUserPostsWeb (postController.js) هر بار پروفایل باز می‌شه دقیقاً // همین سه فیلد رو فیلتر و createdAt رو سورت می‌کنن — بدونِ ایندکس یه scan کامل + // sort توی حافظه‌ست modelSchema.index({ user_id: 1, status: 1, is_archived: 1, createdAt: -1 }); modelSchema.plugin(timestamp); modelSchema.plugin(mongoosePaginate); const PostModel = mongoose.model('Post', modelSchema); module.exports = PostModel;