flexbiz-server
Version:
Flexible Server
7 lines (6 loc) • 2.46 kB
JavaScript
'use strict';const model=global.getModel("dmphi"),controller=require("../../controllers/controller");
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,"dmphi",{sort:{sysorder:1,stt:1},unique:["ma_phi"]});$contr_router$$.route();const $getSysorder$$=function($item$$,$callback$$){let $sysorder$$=($item$$.stt||"0")+$item$$.ma_phi.toString();$item$$.ma_phi_me?model.findOne({ma_phi:$item$$.ma_phi_me,id_app:$item$$.id_app}).lean().exec(function($e$$,$item_me$$){$item_me$$?$getSysorder$$($item_me$$,function($rs$$){$sysorder$$=$rs$$+"-"+$sysorder$$;$callback$$($sysorder$$)}):
$callback$$($sysorder$$)}):$callback$$($sysorder$$)};$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({ma_phi_me:$obj$$.ma_phi,id_app:$obj$$.id_app})&&($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 $ma_phi_me$$=$obj$jscomp$0$$.ma_phi_me;$ma_phi_me$$&&model.findOneAndUpdate({id_app:$obj$jscomp$0$$.id_app,ma_phi:$ma_phi_me$$},{$set:{loai_nh:0}},function($error$$,$obj$$){$error$$?console.error($error$$):$obj$$?console.log("updated "+$obj$$._id):console.log("Not found mother account:"+$ma_phi_me$$)})});$contr_router$$.on("deleted",function($obj$jscomp$0$$){$obj$jscomp$0$$.ma_phi_me&&model.findOne({ma_phi_me:$obj$jscomp$0$$.ma_phi_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,ma_phi:$obj$jscomp$0$$.ma_phi_me},{$set:{loai_nh:1}},function($error$$,$obj$$){$error$$||$obj$$&&console.log("updated "+$obj$$.ma_phi)})})})};