UNPKG

flexbiz-server

Version:

Flexible Server

7 lines (6 loc) 2.83 kB
'use strict';const model=global.getModel("group"),controller=require("../../controllers/controller"),getSysorder=function($item$$,$callback$$){let $sysorder$$=$item$$._id.toString();$item$$.group_mother?model.findOne({_id:$item$$.group_mother}).lean().exec(function($e$$,$item_me$$){$item_me$$?getSysorder($item_me$$,function($rs$$){$sysorder$$=$rs$$+"---"+$sysorder$$;$callback$$($sysorder$$)}):$callback$$($sysorder$$)}):$callback$$($sysorder$$)},dmntt=function($contr_router$$){$contr_router$$=new controller($contr_router$$, model,"dmntt",{sort:{sysorder:1},findExact:{group_type:1},notNeedRight:($user$$,$options$$={})=>"view"==($options$$.action||"").toLowerCase()?!0:!1,keyValues:{group_type:"PROPERTY"},onUpdating:async($user$$,$data$$,$obj$$,$next$$)=>{if($data$$.group_mother&&0<=(await model.getAllChildrenGroup($obj$$.id_app,$obj$$._id.toString())).indexOf($data$$.group_mother))return $next$$("Kh\u00f4ng th\u1ec3 ch\u1ecdn nh\u00f3m n\u00e0y l\u00e0m nh\u00f3m m\u1eb9");$next$$(null,$data$$,$obj$$)}});$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({group_mother:$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 $group_mother$$=$obj$jscomp$0$$.group_mother;$group_mother$$&&model.findOneAndUpdate({id_app:$obj$jscomp$0$$.id_app,_id:$group_mother$$},{$set:{loai_nh:0}},function($error$$,$obj$$){$error$$?console.error($error$$):$obj$$?console.log("updated "+$obj$$._id):console.log("Not found mother account:"+$group_mother$$)})});$contr_router$$.on("deleted",function($obj$jscomp$0$$){$obj$jscomp$0$$.group_mother&&model.findOne({group_mother:$obj$jscomp$0$$.group_mother},function($error$jscomp$0$$, $acc$$){$error$jscomp$0$$||$acc$$||model.findOneAndUpdate({id_app:$obj$jscomp$0$$.id_app,_id:$obj$jscomp$0$$.group_mother},{$set:{loai_nh:1}},function($error$$,$obj$$){$error$$||$obj$$&&console.log("updated "+$obj$$._id)})})})};module.exports=dmntt;