flexbiz-server
Version:
Flexible Server
5 lines (4 loc) • 1.66 kB
JavaScript
const permission=require("../libs/permission"),createRouteHandler=async($ctrl$$,$req$$,$callback$$)=>{const {routeName:$routeName$$,route_action_key:$route_action_key$$,_options:$_options$$}=$req$$;let $notNeedRight$$=$_options$$.notNeedRight||await $ctrl$$.notNeedRight($req$$.user),$res_send$$=!1;if($ctrl$$.options.require_id_app===!1)try{$ctrl$$[$route_action_key$$]($req$$,function($e$$,$rs$$){if($res_send$$)return Logger.error("no id_app route",$routeName$$,"sent header. calback had call");if($e$$){Logger.error("handle create route ",
$routeName$$,$e$$);if($e$$.error)return $res_send$$=!0,$callback$$($e$$);$res_send$$=!0;return $callback$$({error:$e$$.message||$e$$})}$res_send$$=!0;return $callback$$(null,$rs$$)})}catch($e$$){return $res_send$$=!0,$callback$$({error:$e$$.message||$e$$})}else permission.hasRight($req$$.params.id_app,$req$$.user.email,$ctrl$$.module,$_options$$?.action_code||"view",function($error$$,$hr$$){if($res_send$$)return Logger.error("route",$routeName$$,"sent header. hasRight had call");if($hr$$)try{$ctrl$$[$route_action_key$$]($req$$,
function($e$$,$rs$$){if($res_send$$)return Logger.error("route",$routeName$$,"sent header. calback had call");if($e$$){Logger.error("handle create route ",$routeName$$,$e$$);if($e$$.error)return $res_send$$=!0,$callback$$($e$$);$res_send$$=!0;return $callback$$({error:$e$$.message||$e$$})}$res_send$$=!0;return $callback$$(null,$rs$$)})}catch($e$$){return $callback$$({error:$e$$.message||$e$$})}else $res_send$$=!0,$callback$$({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xem b\u00e1o c\u00e1o n\u00e0y"})},
{notNeedRight:$notNeedRight$$})};module.exports=createRouteHandler;