UNPKG

flexbiz-server

Version:

Flexible Server

8 lines (7 loc) 2.86 kB
const usergroupSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},group_name:{type:String,required:!0,maxlength:1024},ds_phu_trach:[String],phan_loai:String,is_customer_group:{type:Boolean,default:!1},is_employee_group:{type:Boolean,default:!1},is_partner_group:{type:Boolean,default:!1},is_agent_group:{type:Boolean,default:!1},is_pttt_group:{type:Boolean,default:!1},default_group:Boolean,tang_duoc_gioi_thieu:Number,tang_gioi_thieu:Number,ty_le_hoa_hong:Number,tang_gioi_thieu_pt:Number, ty_le_hoa_hong_pt:Number,tang_gioi_thieu_denom:String,group_mother:String,loai_nh:{type:Number,default:1},bac:Number,sysorder:String,nh_kh:String,ma_nganh_hang:[String],ma_nvt:[String],mieu_ta_chinh_sach:String,ma_nt:String,allow_signup:{type:Boolean,default:!1},not_need_active:{type:Boolean,default:!1},status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""},visible_to:{type:Number, default:0},visible_to_users:[String],update_right:[String],delete_right:[String],dataview_to:{type:Number,default:0},dataview_to_users:[String]}); (global.configs||{}).createIndexes&&(usergroupSchema.index({id_app:1,is_customer_group:1}),usergroupSchema.index({id_app:1,is_employee_group:1}),usergroupSchema.index({id_app:1,is_partner_group:1}),usergroupSchema.index({id_app:1,is_agent_group:1}),usergroupSchema.index({id_app:1,is_pttt_group:1}),usergroupSchema.index({id_app:1,ds_phu_trach:1}),usergroupSchema.index({id_app:1,group_name:1}),usergroupSchema.index({id_app:1,group_mother:1}),usergroupSchema.index({id_app:1,phan_loai:1}),usergroupSchema.index({id_app:1, default_group:1}),usergroupSchema.index({id_app:1,loai_nh:1}),usergroupSchema.index({id_app:1,bac:1}),usergroupSchema.index({id_app:1,sysorder:1}),usergroupSchema.index({id_app:1,allow_signup:1}),usergroupSchema.index({id_app:1,status:1}),usergroupSchema.index({id_app:1,user_created:1,visible_to:1,visible_to_users:1}),usergroupSchema.index({id_app:1,group_name:"text"}));const model=mongoose.models.usergroup||mongoose.model("usergroup",usergroupSchema); model.referenceKeys={_id:[{model:"participant",key:"group_id",error:"Kh\u00f4ng th\u1ec3 x\u00f3a nh\u00f3m n\u00e0y."}]};model.getInfo=async($id_app$$,$condition$$,$fields$$)=>{$condition$$.id_app=$id_app$$;return new Promise(($resolve$$,$reject$$)=>{model.findOne($condition$$).lean().then($rs$$=>{if(!$rs$$)return $reject$$(Error(`Can't find user group:${$condition$$}`));$resolve$$($fields$$?$rs$$[$fields$$]:$rs$$)}).catch($e$$=>{$reject$$($e$$)})})}; model.getList=async($id_app$$,$condition$$)=>{$condition$$.id_app=$id_app$$;return new Promise(($resolve$$,$reject$$)=>{model.find($condition$$).lean().then($rs$$=>{$resolve$$($rs$$||[])}).catch($e$$=>{$reject$$($e$$)})})};module.exports=model;