UNPKG

flexbiz-server

Version:

Flexible Server

20 lines (19 loc) 9.47 kB
'use strict';const model=global.getModel("bds_floordetail"),controller=require("../../controllers/controller"),trangthai=global.getModel("trangthai"),dmdt=global.getModel("dmdt"),building=global.getModel("bds_building"),floor=global.getModel("bds_floor"),nhadat=global.getModel("bds_nhadat"),group=global.getModel("group"),async=require("async"); module.exports=function($router$$){(new controller($router$$,model,"floordetail",{sort:{stt:1,floor_code:1},unique:["floor_code"],notNeedRight:($user$$,$options$$={})=>"view"==($options$$.action||"").toLowerCase()?!0:!1,onFinding:function($user$$,$_condition$$,$next$$){let $condition$$=Object.assign({},$_condition$$);$condition$$.phone&&($_condition$$["chusohuu.phone"]=$condition$$.phone,delete $_condition$$.phone);$condition$$.so_ct&&($condition$$.so_ct.$regex&&($condition$$.so_ct=$condition$$.so_ct.$regex), $_condition$$.so_ct=$condition$$.so_ct);async.series({nhadat:$callback$$=>{let $$and$$=[];$condition$$.nh_nd&&($condition$$.nh_nd.$regex&&($condition$$.nh_nd=$condition$$.nh_nd.$regex),$$and$$.push({$expr:{$eq:[{$cond:{if:{$in:["$nh_nd",["",null,void 0]]},then:"$nh_nd_goc",else:"$nh_nd"}},$condition$$.nh_nd]}}),delete $_condition$$.nh_nd);if($condition$$.dien_tich_tim_tuong){var $$cond$jscomp$1_$cond$$={$cond:{if:{$in:["$dien_tich_tim_tuong",[0,null,void 0]]},then:"$dien_tich_tim_tuong_goc",else:"$dien_tich_tim_tuong"}}; for(let $key$$ in $condition$$.dien_tich_tim_tuong)$$and$$.push({$expr:{[$key$$]:[$$cond$jscomp$1_$cond$$,$condition$$.dien_tich_tim_tuong[$key$$]]}});delete $_condition$$.dien_tich_tim_tuong}if($condition$$.dien_tich_phong_thuy){$$cond$jscomp$1_$cond$$={$cond:{if:{$in:["$dien_tich_phong_thuy",[0,null,void 0]]},then:"$dien_tich_phong_thuy_goc",else:"$dien_tich_phong_thuy"}};for(var $$cond$jscomp$3_key$$ in $condition$$.dien_tich_phong_thuy)$$and$$.push({$expr:{[$$cond$jscomp$3_key$$]:[$$cond$jscomp$1_$cond$$, $condition$$.dien_tich_phong_thuy[$$cond$jscomp$3_key$$]]}});delete $_condition$$.dien_tich_phong_thuy}if($condition$$.so_phong){$$cond$jscomp$3_key$$={$cond:{if:{$in:["$so_phong",[0,null,void 0]]},then:"$so_phong_goc",else:"$so_phong"}};for(var $$cond$jscomp$4_key$$ in $condition$$.so_phong)$$and$$.push({$expr:{[$$cond$jscomp$4_key$$]:[$$cond$jscomp$3_key$$,$condition$$.so_phong[$$cond$jscomp$4_key$$]]}});delete $_condition$$.so_phong}if($condition$$.so_wc){$$cond$jscomp$4_key$$={$cond:{if:{$in:["$so_wc", [0,null,void 0]]},then:"$so_wc_goc",else:"$so_wc"}};for(var $$cond$jscomp$5_key$$ in $condition$$.so_wc)$$and$$.push({$expr:{[$$cond$jscomp$5_key$$]:[$$cond$jscomp$4_key$$,$condition$$.so_wc[$$cond$jscomp$5_key$$]]}});delete $_condition$$.so_wc}if($condition$$.huong_ban_cong){$$cond$jscomp$5_key$$={$cond:{if:{$in:["$huong_ban_cong",["",null,void 0]]},then:"$huong_ban_cong_goc",else:"$huong_ban_cong"}};for(var $$cond$jscomp$6_key$$ in $condition$$.huong_ban_cong)$$and$$.push({$expr:{[$$cond$jscomp$6_key$$]:[$$cond$jscomp$5_key$$, $condition$$.huong_ban_cong[$$cond$jscomp$6_key$$]]}});delete $_condition$$.huong_ban_cong}if($condition$$.huong_cua_chinh){$$cond$jscomp$6_key$$={$cond:{if:{$in:["$huong_cua_chinh",["",null,void 0]]},then:"$huong_cua_chinh_goc",else:"$huong_cua_chinh"}};for(let $key$$ in $condition$$.huong_cua_chinh)$$and$$.push({$expr:{[$key$$]:[$$cond$jscomp$6_key$$,$condition$$.huong_cua_chinh[$key$$]]}});delete $_condition$$.huong_cua_chinh}0<$$and$$.length&&($_condition$$.$and=$$and$$);$callback$$()}},function($e$$){if($e$$)return $next$$($e$$); $next$$(null,$_condition$$)})},onUpdated:($user$$,$item$$,$next$$)=>{async.series({f:$callback$$=>{floor.findOne({id_app:$item$$.id_app,floor_code:$item$$.floor_code},($e$$,$f$$)=>{$f$$?model.findOneAndUpdate({_id:$item$$._id},{stt:$f$$.stt||0},()=>{$item$$.stt=$f$$.stt;$callback$$(null,$item$$)}):$callback$$(null,$item$$)})},n:$callback$$=>{nhadat.findOne({id_app:$item$$.id_app,ma_nd:$item$$.ma_nd,ma_dt:$item$$.ma_dt,building_code:$item$$.building_code},($_item_e$$,$n$$)=>{$n$$?($_item_e$$={},$_item_e$$.mieu_ta_goc= $n$$.mieu_ta,$_item_e$$.so_phong_goc=$n$$.so_phong,$_item_e$$.so_wc_goc=$n$$.so_wc,$_item_e$$.noi_that_goc=$n$$.noi_that,$_item_e$$.dien_tich_phong_thuy_goc=$n$$.dien_tich_phong_thuy,$_item_e$$.dien_tich_tim_tuong_goc=$n$$.dien_tich_tim_tuong,$_item_e$$.huong_ban_cong_goc=$n$$.huong_ban_cong,$_item_e$$.huong_cua_chinh_goc=$n$$.huong_cua_chinh,$_item_e$$.nh_nd_goc=$n$$.nh_nd,$_item_e$$.noi_that_goc_en=$n$$.noi_that_en,$_item_e$$.mieu_ta_goc_en=$n$$.mieu_ta_en,$_item_e$$.noi_that_goc_en=$n$$.noi_that_en, $_item_e$$.huong_ban_cong_goc_en=$n$$.huong_ban_cong_en,$_item_e$$.huong_cua_chinh_goc_en=$n$$.huong_cua_chinh_en,model.findOneAndUpdate({_id:$item$$._id},$_item_e$$,()=>{$item$$.mieu_ta_goc=$n$$.mieu_ta;$item$$.so_phong_goc=$n$$.so_phong;$item$$.so_wc_goc=$n$$.so_wc;$item$$.noi_that_goc=$n$$.noi_that;$item$$.dien_tich_phong_thuy_goc=$n$$.dien_tich_phong_thuy;$item$$.dien_tich_tim_tuong_goc=$n$$.dien_tich_tim_tuong;$item$$.huong_ban_cong_goc=$n$$.huong_ban_cong;$item$$.huong_cua_chinh_goc=$n$$.huong_cua_chinh; $item$$.nh_nd_goc=$n$$.nh_nd;$item$$.mieu_ta_goc_en=$n$$.mieu_ta_en;$item$$.noi_that_goc_en=$n$$.noi_that_en;$item$$.huong_ban_cong_goc_en=$n$$.huong_ban_cong_en;$item$$.huong_cua_chinh_goc_en=$n$$.huong_cua_chinh_en;$callback$$(null,$item$$)})):$callback$$()})}},()=>{$next$$(null,$item$$)})},onCreated:($user$$,$item$$,$next$$)=>{async.series({f:$callback$$=>{floor.findOne({id_app:$item$$.id_app,floor_code:$item$$.floor_code},($e$$,$f$$)=>{$f$$?model.findOneAndUpdate({_id:$item$$._id},{stt:$f$$.stt|| 0},()=>{$item$$.stt=$f$$.stt;$callback$$(null,$item$$)}):$callback$$(null,$item$$)})},n:$callback$$=>{nhadat.findOne({id_app:$item$$.id_app,ma_nd:$item$$.ma_nd,ma_dt:$item$$.ma_dt,building_code:$item$$.building_code},($_item$jscomp$1_e$$,$n$$)=>{$n$$?($_item$jscomp$1_e$$={},$_item$jscomp$1_e$$.mieu_ta_goc=$n$$.mieu_ta,$_item$jscomp$1_e$$.so_phong_goc=$n$$.so_phong,$_item$jscomp$1_e$$.so_wc_goc=$n$$.so_wc,$_item$jscomp$1_e$$.noi_that_goc=$n$$.noi_that,$_item$jscomp$1_e$$.dien_tich_phong_thuy_goc=$n$$.dien_tich_phong_thuy, $_item$jscomp$1_e$$.dien_tich_tim_tuong_goc=$n$$.dien_tich_tim_tuong,$_item$jscomp$1_e$$.huong_ban_cong_goc=$n$$.huong_ban_cong,$_item$jscomp$1_e$$.huong_cua_chinh_goc=$n$$.huong_cua_chinh,$_item$jscomp$1_e$$.nh_nd_goc=$n$$.nh_nd,$_item$jscomp$1_e$$.mieu_ta_goc_en=$n$$.mieu_ta_en,$_item$jscomp$1_e$$.noi_that_goc_en=$n$$.noi_that_en,$_item$jscomp$1_e$$.huong_ban_cong_goc_en=$n$$.huong_ban_cong_en,$_item$jscomp$1_e$$.huong_cua_chinh_goc_en=$n$$.huong_cua_chinh_en,model.findOneAndUpdate({_id:$item$$._id}, $_item$jscomp$1_e$$,()=>{$item$$.mieu_ta_goc=$n$$.mieu_ta;$item$$.so_phong_goc=$n$$.so_phong;$item$$.so_wc_goc=$n$$.so_wc;$item$$.noi_that_goc=$n$$.noi_that;$item$$.dien_tich_phong_thuy_goc=$n$$.dien_tich_phong_thuy;$item$$.dien_tich_tim_tuong_goc=$n$$.dien_tich_tim_tuong;$item$$.huong_ban_cong_goc=$n$$.huong_ban_cong;$item$$.huong_cua_chinh_goc=$n$$.huong_cua_chinh;$item$$.nh_nd_goc=$n$$.nh_nd;$item$$.mieu_ta_goc_en=$n$$.mieu_ta_en;$item$$.noi_that_goc_en=$n$$.noi_that_en;$item$$.huong_ban_cong_goc_en= $n$$.huong_ban_cong_en;$item$$.huong_cua_chinh_goc_en=$n$$.huong_cua_chinh_en;$callback$$(null,$item$$)})):$callback$$()})}},()=>{$next$$(null,$item$$)})},onView:function($user$$,$items$$,$next$$,$options$$){async.series({updateSoct:$callback$jscomp$0$$=>{async.mapSeries($items$$,($item$$,$callback$$)=>{$item$$.so_ct?$callback$$():(()=>{try{model.findOne({_id:$item$$._id},{so_ct:1},async($e$$,$_obj$$)=>{$_obj$$.so_ct?$callback$$():($e$$=await this.asyncGetNextSequence($item$$.id_app,this.name),$item$$.so_ct= $e$$.so_ct,model.findOneAndUpdate({_id:$item$$._id},{so_ct:$item$$.so_ct},()=>{console.log("update so_ct",$item$$.so_ct);$callback$$()}))})}catch($e$$){console.log("error get next so_ct",$e$$),$callback$$()}})()},()=>{$callback$jscomp$0$$()})},dmdt:$callback$$=>{$items$$.filter($i$$=>$i$$.ma_dt).joinModel2(null,dmdt,{where:{id_app:"id_app",ma_dt:"ma_dt"},fields:["ten_dt","ten_dt_en","tinh_thanh","quan_huyen",{dt_id:"_id"}]},function(){$callback$$(null)})},building:$callback$$=>{$items$$.filter($i$$=> $i$$.building_code).joinModel2(null,building,{where:{id_app:"id_app",building_code:"building_code"},fields:["building_name","building_name_en",{building_id:"_id"}]},function(){$callback$$(null)})},department:$callback$$=>{$items$$.filter($i$$=>$i$$.ma_nd).joinModel2(null,nhadat,{where:{id_app:"id_app",ma_nd:"ma_nd"},fields:["ten_nd","ten_nd_en",{nd_id:"_id"}]},function(){$items$$.joinModel2(null,group,{where:{nh_nd_goc:"_id"},fields:[{group_name_goc:"group_name"},{group_name_goc_en:"group_name_en"}]}, function(){$callback$$(null)})})},floor:$callback$$=>{$items$$.joinModel2(null,floor,{where:{id_app:"id_app",floor_code:"floor_code"},fields:["floor_name","floor_name_en","floor_type","floor_type_en"]},function(){$callback$$(null)})},nhom:$callback$$=>{$items$$.filter($i$$=>$i$$.nh_nd).joinModel2(null,group,{where:{nh_nd:"_id"},fields:["group_name","group_name_en"]},function(){$callback$$(null)})},trangthai:$callback$$=>{$items$$.filter($i$$=>$i$$.trang_thai).joinModel2(null,trangthai,[{where:$a$$=> ({ma_ct:"FLOORDETAIL",ma_trang_thai:$a$$.trang_thai}),fields:["ten_trang_thai","ten_trang_thai_en","color"]}],function(){$callback$$()})}},()=>{$items$$.forEach($r$$=>{$r$$.ban||($r$$.ban={});$r$$.thue||($r$$.thue={});$options$$.shareRoute&&(delete $r$$.chusohuu,delete $r$$.anh_cmnd,delete $r$$.anh_chu_so_huu)});$next$$(null,$items$$)})}})).route()};