UNPKG

flexbiz-server

Version:

Flexible Server

5 lines (4 loc) 1.68 kB
const commentSchema=new Schema({id_app:{type:String},id_product:{type:String},colection_name_product:{type:String},user_created_obj:{type:String},title:{type:String,maxlength:1024},content:{type:String,required:"Vui l\u00f2ng nh\u1eadp n\u1ed9i dung"},url_topic:{type:String,maxlength:1024},is_reply:{type:Boolean,default:!1},id_reply:{type:String},reply_for:String,id_topic:String,shared:{type:Boolean,default:!0},attends:[String],rate:{type:Number,default:0},status:{type:Boolean,default:!0},name:{type:String}, date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""}});(global.configs||{}).createIndexes&&(commentSchema.index({id_app:1,title:"text",content:"text"}),commentSchema.index({id_app:1,id_product:1,id_reply:1}),commentSchema.index({shared:1}),commentSchema.index({id_app:1,status:1}),commentSchema.index({id_app:1,user_created:1,visible_to:1,visible_to_users:1}),commentSchema.index({id_app:1,attends:1})); const model=mongoose.models.comment||mongoose.model("comment",commentSchema);model.getInfo=async($condition$$,$fields$$)=>new Promise(($resolve$$,$reject$$)=>{model.findOne($condition$$).lean().then($rs$$=>{if(!$rs$$)return $reject$$(Error("Can't find comment"));$resolve$$($fields$$?$rs$$[$fields$$]:$rs$$)}).catch($e$$=>{$reject$$(Error($e$$.message))})}); model.getRelativeComments=async function($id_reply$$){let $condition$$={$or:[{id_reply:$id_reply$$},{_id:$id_reply$$}]};return new Promise(($resolve$$,$reject$$)=>{model.find($condition$$).lean().then($rs$$=>{$resolve$$($rs$$)}).catch($e$$=>{$reject$$(Error($e$$.message))})})};module.exports=model;