flexbiz-server
Version:
Flexible Server
11 lines (10 loc) • 3.78 kB
JavaScript
'use strict';const _=require("lodash"),groupSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},group_kind:{type:Number,default:1},group_type:{type:String,uppercase:!0,required:!0,maxlength:1024},group_name:{type:String,required:!0,maxlength:1024},group_name_en:{type:String,maxlength:1024},group_mother:String,ma_kho:{type:String,maxlength:32},ma_bp:{type:String,maxlength:32},ma_dt:{type:String,maxlength:32},color:{type:String,maxlength:32},muc_tieu_bieu:{type:Number,default:0},ma_doi_tuong_danh_gia_default:{type:String},
id_link:String,collection_link:String,phu_trach:String,sysorder:String,bac:{type:Number},loai_nh:{type:Number,default:1},attends:[],dac_thu:Schema.Types.Mixed,exfields:Schema.Types.Mixed,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],visible_to_usergroups:[String],update_right:[String],delete_right:[String],
dataview_to:{type:Number,default:0},dataview_to_users:[String]});
(global.configs||{}).createIndexes&&(groupSchema.index({id_app:1,group_type:1,ma_dt:1,ma_bp:1}),groupSchema.index({group_type:1}),groupSchema.index({group_kind:1}),groupSchema.index({group_mother:1}),groupSchema.index({group_name:1}),groupSchema.index({ma_kho:1}),groupSchema.index({ma_dt:1}),groupSchema.index({ma_bp:1}),groupSchema.index({sysorder:1}),groupSchema.index({bac:1}),groupSchema.index({loai_nh:1}),groupSchema.index({phu_trach:1}),groupSchema.index({id_link:1}),groupSchema.index({status:1}),
groupSchema.index({attends:1}),groupSchema.index({group_name:"text",group_type:"text"},{name:"group_index_text"}),groupSchema.index({status:1}),groupSchema.index({user_created:1,visible_to:1,visible_to_users:1}));const model=mongoose.models.group||mongoose.model("group",groupSchema);model.referenceKeys={_id:[{model:"task",key:"nh_cv",error:"Nh\u00f3m n\u00e0y \u0111\u00e3 c\u00f3 ph\u00e1t sinh chi ti\u1ebft. B\u1ea1n c\u1ea7n xo\u00e1 t\u1ea5t c\u1ea3 chi ti\u1ebft tr\u01b0\u1edbc khi xo\u00e1 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().exec(($e$$,$rs$$)=>{if($e$$||!$rs$$)return $reject$$(Error($e$$?$e$$.message:"Can't find information"));$resolve$$($fields$$?$rs$$[$fields$$]:$rs$$)})})};
model.getAllChildrenGroup=async($id_app$$,$nh_kh_rs$$,$chil_condition$$={})=>{let $nh_khs$$;$nh_khs$$=_.isArray($nh_kh_rs$$)?[...$nh_kh_rs$$]:[$nh_kh_rs$$];$nh_kh_rs$$=[...$nh_khs$$];$chil_condition$$=(await model.find({id_app:$id_app$$,group_mother:{$in:$nh_khs$$},...$chil_condition$$},{_id:1,group_mother:1}).lean()).filter($n$$=>$n$$._id.toString()!=$n$$.group_mother).map($d$$=>$d$$._id);0<$chil_condition$$.length&&($chil_condition$$=await Promise.all($chil_condition$$.map($nh$$=>model.getAllChildrenGroup($id_app$$,
$nh$$))),$chil_condition$$=$chil_condition$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]),$nh_kh_rs$$=[...$chil_condition$$,...$nh_kh_rs$$]);return $nh_kh_rs$$};
model.getAllMotherGroup=async($group_mother_id_app$$,$nh_kh$jscomp$1_rs$$,$condition$$={})=>{$nh_kh$jscomp$1_rs$$=[...(_.isArray($nh_kh$jscomp$1_rs$$)?[...$nh_kh$jscomp$1_rs$$]:[$nh_kh$jscomp$1_rs$$])];$condition$$=await model.findOne({id_app:$group_mother_id_app$$,_id:{$in:$nh_kh$jscomp$1_rs$$},...$condition$$},{_id:1,group_mother:1}).lean();if(!$condition$$||!$condition$$.group_mother)return $nh_kh$jscomp$1_rs$$;$group_mother_id_app$$=await model.getAllMotherGroup($group_mother_id_app$$,$condition$$.group_mother);
return $nh_kh$jscomp$1_rs$$=[...$nh_kh$jscomp$1_rs$$,...$group_mother_id_app$$]};module.exports=model;