UNPKG

kpiplus

Version:

KPI+

1 lines 1.45 kB
var model=require("../../models/dmto"),dmbp=require("../../models/dmbp"),dmdoi=require("../../models/dmdoi"),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,"dmto",{sort:{ma_bp:1,ma_doi:1,ma_to:1},unique:["ma_to"],onView:function(e,n,r){async.parallel({dp:function(r){n.joinModel2(e.current_id_app,dmbp,[{where:{ma_bp:"ma_bp"},fields:["ten_bp"]}],function(e){r(null,n)})},doi:function(r){n.joinModel2(e.current_id_app,dmdoi,[{where:{ma_doi:"ma_doi",ma_bp:"ma_bp"},fields:["ten_doi"]}],function(e){r(null,n)})},pt:function(e){n.joinModel2(null,User,[{where:{phu_trach:"email"},fields:[{ten_phu_trach:"name"}]}],function(r){e(null,n)})},ph:function(e){n.joinModel2(null,User,[{where:{phoi_hop:"email"},fields:[{ten_phoi_hop:"name"}]}],function(r){e(null,n)})}},()=>{r(null,n)})},onRightByItem:(e,n,r)=>{async.parallel({phu_trach_bp:n=>{dmbp.find({id_app:e.current_id_app,phu_trach:e.email}).lean().exec((e,r)=>{n(null,r)})},phu_trach_doi:n=>{dmdoi.find({id_app:e.current_id_app,phu_trach:e.email}).lean().exec((e,r)=>{n(null,r)})}},(e,o)=>{let i=[{ma_bp:{$in:underscore.pluck(o.phu_trach_bp,"ma_bp")}},{ma_doi:{$in:underscore.pluck(o.phu_trach_doi,"ma_doi")}}],l=[];for(let e in n){let r={};r[e]=n[e],l.push(r)}i.push({$and:l}),r(null,{$or:i})})}})).route()};