flexbiz-server
Version:
Flexible Server
7 lines (6 loc) • 2.4 kB
JavaScript
const task=global.getModel("task"),dmbp=global.getModel("dmbp"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),user=global.getModel("user"),group=global.getModel("group"),controller=require("../../controllers/controllerRPT"),moment=require("moment");
module.exports=function($router$$){new controller($router$$,"congviectheotimeline",async($req$$,$callback$$)=>{const $condition$$=$req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");const $query$$={id_app:$condition$$.id_app};$condition$$.tu_ngay=moment(new Date($condition$$.tu_ngay)).startOf("date").toDate();$condition$$.den_ngay=moment(new Date($condition$$.den_ngay)).endOf("date").toDate();
$query$$.start_date={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};if($condition$$.id_bp)try{let $_ch$$=await dmbp.getChilren($condition$$.id_app,$condition$$.id_bp);$_ch$$.push($condition$$.id_bp);$query$$.id_bp={$in:$_ch$$}}catch($e$$){Logger.info($e$$)}$condition$$.id_kh&&($query$$.id_kh=$condition$$.id_kh);$condition$$.id_dt&&($query$$.id_dt=$condition$$.id_dt);$condition$$.id_bp&&($query$$.id_bp=$condition$$.id_bp);$condition$$.phu_trach&&($query$$.phu_trach=$condition$$.phu_trach);$condition$$.nh_cv&&
($query$$.nh_cv=$condition$$.nh_cv);task.find($query$$).lean().exec(async($error$$,$report$$)=>{if($error$$)return Logger.info($error$$,$query$$),$callback$$($error$$);await $report$$.filter($item$$=>$item$$.id_bp).asyncJoinModel2($condition$$.id_app,dmbp,{where:{id_bp:"_id"},fields:["ma_bp","ten_bp"]});await $report$$.filter($item$$=>$item$$.id_dt).asyncJoinModel2($condition$$.id_app,dmdt,{where:{id_dt:"_id"},fields:["ma_dt","ten_dt"]});await $report$$.filter($item$$=>$item$$.id_kh).asyncJoinModel2($condition$$.id_app,
customer,{where:{id_kh:"_id"},fields:["ma_kh","ten_kh"]});await $report$$.filter($item$$=>$item$$.phu_trach).asyncJoinModel2(null,user,{where:{phu_trach:"email"},fields:[{ten_phu_trach:"name"}]});await $report$$.filter($item$$=>$item$$.nh_cv).asyncJoinModel2($condition$$.id_app,group,{where:{nh_cv:"_id"},fields:[{ten_nh_cv:"group_name"}]});for(let $t$$ of $report$$.filter($item$$=>$item$$.cv_phu_thuoc&&$item$$.cv_phu_thuoc.length>0))$t$$.cv_phu_thuoc=$t$$.cv_phu_thuoc.filter($c$$=>$report$$.find($r$$=>
$r$$._id==$c$$)&&$t$$._id!=$c$$);$callback$$(null,$report$$)})})};