UNPKG

flexbiz-server

Version:

Flexible Server

9 lines (8 loc) 3.31 kB
'use strict';const model=global.getModel("dmnvt"),controller=require("../../controllers/controller"),underscore=require("underscore"); module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,"dmnvt",{sort:{sysorder:1},notNeedRight:($user$$,$options$$={})=>"view"==($options$$.action||"").toLowerCase()?!0:!1,onView:function($user$$,$items$$,$next$$){$items$$.filter($item$$=>$item$$.nh_me).joinModel2($user$$.current_id_app,model,[{where:{nh_me:"_id"},fields:[{name:"ten_nh_me",value:"ten_nvt"}]}],function(){$items$$=underscore.sortBy($items$$,function($item$$){return $item$$.sysorder});$items$$.forEach(async $item$$=> {!$item$$.ma_nganh_hang||$item$$.ds_nganh_hang&&0!=$item$$.ds_nganh_hang.length||($item$$.ds_nganh_hang=[$item$$.ma_nganh_hang],await model.updateOne({_id:$item$$._id},{ds_nganh_hang:$item$$.ds_nganh_hang}))});$next$$(null,$items$$)})},onUpdating:async($user$$,$data$$,$obj$$,$next$$)=>{if($data$$.nh_me&&0<=(await model.getAllChildrenGroup($obj$$.id_app,$obj$$._id.toString())).indexOf($data$$.nh_me))return $next$$("Kh\u00f4ng th\u1ec3 ch\u1ecdn nh\u00f3m n\u00e0y l\u00e0m nh\u00f3m m\u1eb9");$next$$(null, $data$$,$obj$$)}});const $getSysorder$$=function($item$$,$callback$$){let $sysorder$$=($item$$.stt||"0")+$item$$._id.toString();$item$$.nh_me?model.findOne({_id:$item$$.nh_me}).lean().exec(function($e$$,$item_me$$){$item_me$$?$getSysorder$$($item_me$$,function($rs$$){$sysorder$$=$rs$$+"-"+$sysorder$$;$callback$$($sysorder$$)}):$callback$$($sysorder$$)}):$callback$$($sysorder$$)};$contr_router$$.route();$contr_router$$.deleting=function($user$$,$obj$$,$next$$){if(0===$obj$$.loai_nh)return $next$$(Error("Kh\u00f4ng \u0111\u01b0\u1ee3c ph\u00e9p x\u00f3a nh\u00f3m m\u1eb9")); $next$$(null,$obj$$)};$contr_router$$.created=function($user$$,$obj$$,$next$$){$getSysorder$$($obj$$,function($rs$$){$obj$$.sysorder=$rs$$;$obj$$.bac=$rs$$.split("-").length;model.findOneAndUpdate({_id:$obj$$._id},{$set:{bac:$obj$$.bac,sysorder:$obj$$.sysorder,loai_nh:1}},function($e$$){$e$$&&console.log($e$$)});$next$$(null,$obj$$)})};$contr_router$$.updated=function($user$$,$obj$$,$next$$){$getSysorder$$($obj$$,async function($loai_nh_rs$$){$obj$$.sysorder=$loai_nh_rs$$;$obj$$.bac=$loai_nh_rs$$.split("-").length; $loai_nh_rs$$=1;await model.findOne({nh_me:$obj$$._id.toString()})&&($loai_nh_rs$$=0);$obj$$.loai_nh=$loai_nh_rs$$;model.findOneAndUpdate({_id:$obj$$._id},{$set:{bac:$obj$$.bac,sysorder:$obj$$.sysorder,loai_nh:$loai_nh_rs$$}},function($e$$){$e$$&&console.log($e$$)});$next$$(null,$obj$$)})};$contr_router$$.on("saved",function($obj$jscomp$0$$){const $nh_me$$=$obj$jscomp$0$$.nh_me;$nh_me$$&&model.findOneAndUpdate({id_app:$obj$jscomp$0$$.id_app,_id:$nh_me$$},{$set:{loai_nh:0}},function($error$$,$obj$$){$error$$? console.error($error$$):$obj$$?console.log("updated "+$obj$$._id):console.log("Not found mother account:"+$nh_me$$)})});$contr_router$$.on("deleted",function($obj$jscomp$0$$){$obj$jscomp$0$$.nh_me&&model.findOne({nh_me:$obj$jscomp$0$$.nh_me,id_app:$obj$jscomp$0$$.id_app},function($error$jscomp$0$$,$acc$$){$error$jscomp$0$$||$acc$$||model.findOneAndUpdate({id_app:$obj$jscomp$0$$.id_app,_id:$obj$jscomp$0$$.nh_me},{$set:{loai_nh:1}},function($error$$,$obj$$){$error$$||$obj$$&&console.log("updated "+ $obj$$._id)})})})};