flexbiz-server
Version:
Flexible Server
13 lines (12 loc) • 4.72 kB
JavaScript
const dmbpSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},ma_bp:{type:String,required:!0,uppercase:!0,maxlength:32},ten_bp:{type:String,required:!0,maxlength:1024},phu_trach:{type:String,uppercase:!0,maxlength:1024},ten_phu_trach:String,phoi_hop:{type:String,uppercase:!0,maxlength:1024},ma_bp_me:{type:String,uppercase:!0,maxlength:32},ma_bp_tuong_tac:[String],nhiem_vu:{type:String},tk_cp_luong:String,tk_pt_nv:String,tk_thue_tncn:String,ma_phi:String,tinh_luong_theo_ngay:Boolean,
ma_loai_cong_mac_dinh:String,sysorder:String,bac:{type:Number},loai_nh:{type:Number,default:1},phu_cap:[],la_cong_doan_sx:{type:Boolean,default:!1},stt:Number,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],update_right:[String],delete_right:[String],dataview_to:{type:Number,
default:0},dataview_to_users:[String]},{toJSON:{virtuals:!0}});
(global.configs||{}).createIndexes&&(dmbpSchema.index({id_app:1,ma_bp:1},{unique:!0}),dmbpSchema.index({id_app:1,ma_bp:1,ten_bp:1}),dmbpSchema.index({id_app:1,ma_bp:1,ten_bp:1,sysorder:1,bac:1,loai_nh:1}),dmbpSchema.index({id_app:1,phu_trach:1,ten_phu_trach:1}),dmbpSchema.index({id_app:1,status:1}),dmbpSchema.index({id_app:1,ma_bp_me:1}),dmbpSchema.index({id_app:1,ma_bp_tuong_tac:1}),dmbpSchema.index({id_app:1,nhiem_vu:1}),dmbpSchema.index({id_app:1,ma_loai_cong_mac_dinh:1}),dmbpSchema.index({id_app:1,
user_created:1,visible_to:1,visible_to_users:1,status:1}),dmbpSchema.index({id_app:1,ma_bp:"text",ten_bp:"text",phu_trach:"text",ten_phu_trach:"text"},{name:"dmbp_index_text"}));const model=mongoose.models.dmbp||mongoose.model("dmbp",dmbpSchema);
model.referenceKeys={ma_bp:[{model:"socai",key:"ma_bp",error:"B\u1ed9 ph\u1eadn {{VALUE}} \u0111\u00e3 ph\u00e1t sinh d\u1eef li\u1ec7u trong s\u1ed5 c\u00e1i"},{model:"chamcong",key:"ma_bp",error:"B\u1ed9 ph\u1eadn {{VALUE}} \u0111\u00e3 ph\u00e1t sinh d\u1eef li\u1ec7u trong b\u1ea3ng ch\u1ea5m c\u00f4ng"},{model:"bangtinhluong",key:"ma_bp",error:"B\u1ed9 ph\u1eadn {{VALUE}} \u0111\u00e3 ph\u00e1t sinh d\u1eef li\u1ec7u trong b\u1ea3ng t\u00ednh l\u01b0\u01a1ng"},{model:"qts",key:"ma_bp",error:"B\u1ed9 ph\u1eadn {{VALUE}} \u0111\u00e3 ph\u00e1t sinh d\u1eef li\u1ec7u trong qu\u1ea3n l\u00fd t\u00e0i s\u1ea3n"},
{model:"phieudanhgia",key:"ma_bp",error:"B\u1ed9 ph\u1eadn {{VALUE}} \u0111\u00e3 ph\u00e1t sinh d\u1eef li\u1ec7u trong phi\u1ebfu \u0111\u00e1nh gi\u00e1 nh\u00e2n vi\u00ean"},{model:"dmnv",key:"ma_bp",error:"B\u1ed9 ph\u1eadn {{VALUE}} \u0111\u00e3 ph\u00e1t sinh nh\u00e2n vi\u00ean"},{model:"dmbp",key:"ma_bp_me",error:"B\u1ed9 ph\u1eadn {{VALUE}} c\u00f3 b\u1ed9 ph\u1eadn con"}]};
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 data"));$resolve$$($fields$$?$rs$$[$fields$$]:$rs$$)}).catch($e$$=>{$reject$$($e$$.message)})})};
model.getChilren=async($id_app$$,$id$$)=>{let $_bp$$=await model.getInfo($id_app$$,{_id:$id$$});return new Promise(($resolve$$,$reject$$)=>{model.find({id_app:$id_app$$,ma_bp_me:$_bp$$.ma_bp}).lean().then(async $_mbp__rs$$=>{$_mbp__rs$$=$_mbp__rs$$.map($r$$=>$r$$._id);let $rs$$=[].concat($_mbp__rs$$);for(let $i$$=0;$i$$<$_mbp__rs$$.length;$i$$++)$_mbp__rs$$=await model.getChilren($id_app$$,$_mbp__rs$$[$i$$]),$rs$$=$rs$$.concat($_mbp__rs$$);$resolve$$($rs$$)}).catch($e$$=>{$reject$$(Error($e$$.message))})})};
model.getChilrenByMaBP=async($id_app$$,$ma_bp$$)=>{let $_bp$$=await model.getInfo($id_app$$,{ma_bp:$ma_bp$$});return new Promise(($resolve$$,$reject$$)=>{model.find({id_app:$id_app$$,ma_bp_me:$_bp$$.ma_bp}).lean().then(async $_mbp$jscomp$1__rs$$=>{$_mbp$jscomp$1__rs$$=$_mbp$jscomp$1__rs$$.map($r$$=>$r$$.ma_bp);let $rs$$=[].concat($_mbp$jscomp$1__rs$$);for(let $i$$=0;$i$$<$_mbp$jscomp$1__rs$$.length;$i$$++)$_mbp$jscomp$1__rs$$=await model.getChilrenByMaBP($id_app$$,$_mbp$jscomp$1__rs$$[$i$$]),$rs$$=
$rs$$.concat($_mbp$jscomp$1__rs$$);$resolve$$($rs$$)}).catch($e$$=>{$reject$$(Error($e$$.message))})})};model.getEmployeesByMaBP=async($id_app$$,$all_bp_ma_bp$$)=>{let $chilrends$$=await model.getChilrenByMaBP($id_app$$,$all_bp_ma_bp$$);$all_bp_ma_bp$$=[$all_bp_ma_bp$$,...$chilrends$$];return await global.getModel("dmnv").find({id_app:$id_app$$,ma_bp:{$in:$all_bp_ma_bp$$}})};
model.getUsersByMaBP=async($id_app$$,$ma_bp$$)=>(await model.getEmployeesByMaBP($id_app$$,$ma_bp$$)).map($e$$=>$e$$.user).filter($e$$=>$e$$);module.exports=model;