kpiplus
Version:
KPI+
1 lines • 1.16 kB
JavaScript
var model=require("../../models/dmban"),group=require("../../models/group"),controller=require("../../controllers/controller"),async=require("async"),_=require("underscore");module.exports=function(n){(this.contr=new controller(n,model,"dmban",{sort:{stt:1,ten_ban:1},unique:["ma_ban"],onFinding:(n,e,o)=>{e.ma_kho?group.find({id_app:n.current_id_app,group_type:"TABLE",ma_kho:e.ma_kho},{_id:1}).lean().exec((n,r)=>{if(n)return o(n);delete e.ma_kho;let l=[{$or:[{nh_ban:{$in:_.pluck(r,"_id")}},{nh_ban:null},{nh_ban:""}]}];e.$or&&l.push({$or:e.$or}),delete e.$or,e.$and=l,o(null,e)}):o(null,e)},onView:function(n,e,o){async.parallel({grp:function(o){e.joinModel(n.current_id_app,group,[{where:{_id:"nh_ban"},fields:[{name:"ten_nh_ban",value:"group_name"}]}],function(n){o(null)})},loai:function(o){e.joinModel(n.current_id_app,group,[{where:{_id:"loai_ban"},fields:[{name:"ten_loai_ban",value:"group_name"}]}],function(n){o(null)})},trang_thai:function(o){e.joinModel(n.current_id_app,group,[{where:{_id:"trang_thai"},fields:[{name:"ten_trang_thai",value:"group_name"},{name:"color",value:"color"}]}],function(n){o(null)})}},function(n,r){o(null,e)})}})).route()};