flexbiz-server
Version:
Flexible Server
5 lines (4 loc) • 1.65 kB
JavaScript
'use strict';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(!1===$ctrl$$.options.require_id_app)try{$ctrl$$[$route_action_key$$]($req$$,function($e$$,$rs$$){if($res_send$$)return console.error("no id_app route",$routeName$$,"sent header. calback had call");
if($e$$){console.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,"view",function($error$$,$hr$$){if($res_send$$)return console.error("route",$routeName$$,"sent header. hasRight had call");
if($hr$$)try{$ctrl$$[$route_action_key$$]($req$$,function($e$$,$rs$$){if($res_send$$)return console.error("route",$routeName$$,"sent header. calback had call");if($e$$){console.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;