Files
modstagram-back/models/CommentModel.js
payacom 3f416a7a60 full
2026-08-31 20:45:41 +03:30

72 lines
1.7 KiB
JavaScript

const mongoose = require('mongoose')
const timestamp = require('mongoose-timestamp')
const mongoosePaginate = require('mongoose-paginate-v2')
const commentSchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
project: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Project',
required: false
},
offer: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Offer',
required: false
},
creator: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
rating: {
type: Number,
required: false,
default: null
},
comment: {
type: String,
trim: true
},
post: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Post',
required: false
},
shop_product: {
type: mongoose.Schema.Types.ObjectId,
ref: 'ShopProductListing',
required: false
},
parent: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Comment',
required: false,
default: null,
},
comment_for: {
type: String,
enum: ['user', 'project', 'post', 'shop_product'],
required: true
},
status: {
type: String,
enum: ['pending', 'temp_accept', 'accepted', 'rejected'],
default: 'pending'
}
})
// postController.js هر بار جزئیاتِ پست باز می‌شه CommentModel.countDocuments({post,status})
// می‌زنه؛ getUserController.js هم لیستِ کامنت‌های یه کاربر رو با user فیلتر می‌کنه
commentSchema.index({ post: 1, status: 1 })
commentSchema.index({ user: 1 })
commentSchema.plugin(timestamp)
commentSchema.plugin(mongoosePaginate)
const CommentModel = mongoose.model('Comment', commentSchema)
module.exports = CommentModel