kpiplus
Version:
KPI+
1 lines • 1.81 kB
JavaScript
var model=require("../../models/dmnhnv"),dmbp=require("../../models/dmbp"),dmdoi=require("../../models/dmdoi"),dmto=require("../../models/dmto"),User=require("../../models/user"),arrays=require("../../libs/array-funcs"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controller");module.exports=function(e){(this.contr=new controller(e,model,"dmnhnv",{sort:{ma_bp:1,ma_doi:1,ma_to:1,ma_nh_nv:1},unique:["ma_nh_nv"],onView:function(e,n,o){async.parallel({dp:function(o){n.joinModel2(e.current_id_app,dmbp,[{where:{ma_bp:"ma_bp"},fields:["ten_bp"]}],function(e){o(null,n)})},doi:function(o){n.joinModel2(e.current_id_app,dmdoi,[{where:{ma_doi:"ma_doi",ma_bp:"ma_bp"},fields:["ten_doi"]}],function(e){o(null,n)})},to:function(o){n.joinModel2(e.current_id_app,dmto,[{where:{ma_doi:"ma_doi",ma_bp:"ma_bp",ma_to:"ma_to"},fields:["ten_to"]}],function(e){o(null,n)})},pt:function(e){n.joinModel2(null,User,[{where:{phu_trach:"email"},fields:[{ten_phu_trach:"name"}]}],function(o){e(null,n)})},ph:function(e){n.joinModel2(null,User,[{where:{phoi_hop:"email"},fields:[{ten_phoi_hop:"name"}]}],function(o){e(null,n)})}},()=>{o(null,n)})},onRightByItem:(e,n,o)=>{async.parallel({phu_trach_bp:n=>{dmbp.find({id_app:e.current_id_app,phu_trach:e.email}).lean().exec((e,o)=>{n(null,o)})},phu_trach_doi:n=>{dmdoi.find({id_app:e.current_id_app,phu_trach:e.email}).lean().exec((e,o)=>{n(null,o)})},phu_trach_to:n=>{dmto.find({id_app:e.current_id_app,phu_trach:e.email}).lean().exec((e,o)=>{n(null,o)})}},(e,r)=>{let i=[{ma_bp:{$in:underscore.pluck(r.phu_trach_bp,"ma_bp")}},{ma_doi:{$in:underscore.pluck(r.phu_trach_doi,"ma_doi")}},{ma_to:{$in:underscore.pluck(r.phu_trach_doi,"ma_to")}}],l=[];for(let e in n){let o={};o[e]=n[e],l.push(o)}i.push({$and:l}),o(null,{$or:i})})}})).route()};