flexbiz-server 12.0.7 → 12.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/controllers/controller.js +94 -89
- package/server/controllers/controllerRPT.js +12 -12
- package/server/libs/permission.js +14 -15
- package/server/libs/prototypes.js +7 -7
- package/server/libs/thnxt.js +2 -2
- package/server/models/cart.js +3 -3
- package/server/models/dmvt.js +5 -4
- package/server/models/listinfo.js +34 -13
- package/server/models/participant.js +3 -1
- package/server/models/so1.js +1 -1
- package/server/models/tontucthoi.js +2 -2
- package/server/modules/lists/ls-comment.js +3 -3
- package/server/modules/reports/rp-bcintroducebonus.js +2 -2
- package/server/modules/reports/rp-ckvt.js +2 -1
- package/server/modules/vouchers/vo-lenhcapphat.js +1 -1
- package/server/modules/vouchers/vo-so1.js +38 -37
- package/server/route.js +29 -29
package/package.json
CHANGED
|
@@ -34,12 +34,12 @@ $e$$,$approveData_condition$$),!1}});$approveDatas$$.filter($a$$=>$a$$.approve_u
|
|
|
34
34
|
$ds_nguoi_duyet$$.map($nguoi_duyet$$=>({email:$nguoi_duyet$$,name:$nguoi_duyet$$}));$user_approves$$.joinModel2($obj$$.id_app,Participant,{where:"email",fields:"name"},()=>{Approve.request($user_request$$,$user_approves$$,$title$$,$obj$$,$e$$=>{$e$$&&console.error("error create request approve",$e$$.message)},$update_after_approve$$,$approveData$$.template_content)})}})});$next$$(null,$obj$$)}async sendEmailNotification($user$$,$obj$$,$title$$,$callback$jscomp$0$$,$voucher_options$$){$voucher_options$$||
|
|
35
35
|
($voucher_options$$=(await OptionsModel.findOne({id_app:$obj$$.id_app,id_func:this.name},{option:1}).lean()||{}).option);$voucher_options$$&&$voucher_options$$.send_notification_to_users?async.map($voucher_options$$.send_notification_to_users,($u$$,$callback$$)=>{setImmediate(()=>{global.createNotification($obj$$.user_updated,$u$$.email,$title$$,$title$$,($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)},$obj$$,!0,$user$$.c_token,!0)})},$e$$=>{$callback$jscomp$0$$($e$$)}):$callback$jscomp$0$$()}async import($user$$,
|
|
36
36
|
$id_app$$,$data$$,$callback$jscomp$0$$,$options$$={replace:!0,req:null}){const $ctrl$$=this;let $replace$$=$options$$.replace,$rows_error$$=[];const $listInfo$$=global.getModel("listinfo");let $info$$=await $listInfo$$.findOne({code:$ctrl$$.name.toLowerCase()}).lean();$info$$&&await $listInfo$$.updateModel($info$$,$ctrl$$.model);$data$$=$data$$.filter($row$$=>{let $has_data$$=!1;for(let $key$$ in $row$$)if($row$$[$key$$]){$has_data$$=!0;break}return $has_data$$});$data$$.forEach($r$$=>{delete $r$$.ten_dvcs});
|
|
37
|
-
await $data$$.filter($r$$=>$r$$.ma_dvcs).asyncJoinModel2($id_app$$,global.getModel("dvcs"),{where:{ma_dvcs:"_id"},fields:"ten_dvcs"});async.map($data$$,function($row$$,$callback$$){const $row_keys$$=Object.keys($row$$);$row_keys$$.forEach($key$$=>{let $data_type$$=$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase(),$data_value$$=$row$$[$key$$];if($data_value$$&&_.isString($data_value$$)&&("mixed"==$data_type$$||"array"==$data_type$$)&&($data_value
|
|
38
|
-
0==$data_value$$.indexOf("{")))try{$row$$[$key$$]=JSON.parse($data_value$$)}catch($e$$){delete $row$$[$key$$],console.error("Error parse data",$e$$)}});setImmediate(()=>{delete $row$$.__v;$row$$.ma_dvcs&&!$row$$.ten_dvcs&&delete $row$$.ma_dvcs;$id_app$$!=$row$$.id_app&&delete $row$$._id;delete $row$$.id_app;if($replace$$&&$ctrl$$.unique&&0<$ctrl$$.unique.length){let $query$$={};0!=$ctrl$$.require_id_app&&($query$$.id_app=$id_app$$);$ctrl$$.options.unique_imp
|
|
39
|
-
$row$$[$ctrl$$.options.unique_imp]:$ctrl$$.unique.forEach(function($k$$){0<=$row_keys$$.indexOf($k$$)&&($query$$[$k$$]=$row$$[$k$$])});$ctrl$$.model.find($query$$).lean().exec(function($error$$,$rss$$){if(1<$rss$$.length)return $callback$$("Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u1ed1i t\u01b0\u1ee3ng:"+Object.values($query$$).join("-"));setImmediate(()=>{if($error$$)return $callback$$($error$$);if(1===$rss$$.length){let $rs
|
|
40
|
-
$ctrl$$.unique.forEach(function($k$$){$row$$[$k$$]=$rs$$[$k$$]});update($user$$,$ctrl$$,$rs$$._id,$row$$,function($e$$){console.log("updated object...");if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,error:"Error update data:"+$_e$$})}$callback$$()},"import",$options$$.req)}else create($user$$,$ctrl$$,$row$$,function($e$$){console.log("created new object...");if($e$$){let $_e
|
|
41
|
-
error:$_e$$})}$callback$$()},$row$$._id,$options$$.req)})})}else create($user$$,$ctrl$$,$row$$,function($e$$){console.log("created new object...");setImmediate(()=>{if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,error:$_e$$})}$callback$$()})},$row$$._id,$options$$.req)})},function($error$$){setImmediate(()=>{console.log("finish import...");if($error$$)return $callback$jscomp$0$$($error$$);
|
|
42
|
-
rows_error:[]}):$callback$jscomp$0$$(null,{rows_imported:$data$$.length-$rows_error$$.length,rows_error:$rows_error$$})})})}}controller.prototype.__proto__=EventEmitter.prototype;
|
|
37
|
+
await $data$$.filter($r$$=>$r$$.ma_dvcs).asyncJoinModel2($id_app$$,global.getModel("dvcs"),{where:{ma_dvcs:"_id"},fields:"ten_dvcs"});async.map($data$$,function($row$$,$callback$$){const $row_keys$$=Object.keys($row$$);$row_keys$$.filter($key$$=>$ctrl$$.model.schema.paths[$key$$]).forEach($key$$=>{let $data_type$$=$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase(),$data_value$$=$row$$[$key$$];if($data_value$$&&_.isString($data_value$$)&&("mixed"==$data_type$$||"array"==$data_type$$)&&($data_value$$=
|
|
38
|
+
$data_value$$.trim(),0==$data_value$$.indexOf("[")||0==$data_value$$.indexOf("{")))try{$row$$[$key$$]=JSON.parse($data_value$$)}catch($e$$){delete $row$$[$key$$],console.error("Error parse data",$e$$)}});setImmediate(()=>{delete $row$$.__v;$row$$.ma_dvcs&&!$row$$.ten_dvcs&&delete $row$$.ma_dvcs;$id_app$$!=$row$$.id_app&&delete $row$$._id;delete $row$$.id_app;if($replace$$&&$ctrl$$.unique&&0<$ctrl$$.unique.length){let $query$$={};0!=$ctrl$$.require_id_app&&($query$$.id_app=$id_app$$);$ctrl$$.options.unique_imp&&
|
|
39
|
+
$row$$[$ctrl$$.options.unique_imp]?$query$$[$ctrl$$.options.unique_imp]=$row$$[$ctrl$$.options.unique_imp]:$ctrl$$.unique.forEach(function($k$$){0<=$row_keys$$.indexOf($k$$)&&($query$$[$k$$]=$row$$[$k$$])});$ctrl$$.model.find($query$$).lean().exec(function($error$$,$rss$$){if(1<$rss$$.length)return $callback$$("Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u1ed1i t\u01b0\u1ee3ng:"+Object.values($query$$).join("-"));setImmediate(()=>{if($error$$)return $callback$$($error$$);if(1===$rss$$.length){let $rs$$=
|
|
40
|
+
$rss$$[0];$row$$.id_app=$rs$$.id_app;$row$$._id=$rs$$._id.toString();$ctrl$$.unique.forEach(function($k$$){$row$$[$k$$]=$rs$$[$k$$]});update($user$$,$ctrl$$,$rs$$._id,$row$$,function($e$$){console.log("updated object...");if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,error:"Error update data:"+$_e$$})}$callback$$()},"import",$options$$.req)}else create($user$$,$ctrl$$,$row$$,function($e$$){console.log("created new object...");if($e$$){let $_e$$=
|
|
41
|
+
$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,error:$_e$$})}$callback$$()},$row$$._id,$options$$.req)})})}else create($user$$,$ctrl$$,$row$$,function($e$$){console.log("created new object...");setImmediate(()=>{if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,error:$_e$$})}$callback$$()})},$row$$._id,$options$$.req)})},function($error$$){setImmediate(()=>{console.log("finish import...");if($error$$)return $callback$jscomp$0$$($error$$);
|
|
42
|
+
0===$rows_error$$.length?$callback$jscomp$0$$(null,{rows_imported:$data$$.length,rows_error:[]}):$callback$jscomp$0$$(null,{rows_imported:$data$$.length-$rows_error$$.length,rows_error:$rows_error$$})})})}}controller.prototype.__proto__=EventEmitter.prototype;
|
|
43
43
|
const getNextSequence=async function($id_app$$,$ma_ct$$,$field$$,$callback$$,$options$$={}){var $condition_qct_qcts$$={status:!0,field:$field$$,id_app:$id_app$$,$and:[{$or:[{ma_ct:"#",ma_ct_khac:{$regex:$ma_ct$$,$options:"i"}},{cac_ma_ct:$ma_ct$$.toLowerCase()},{ma_ct:$ma_ct$$.toUpperCase()}]}]};$options$$.id_qct&&($condition_qct_qcts$$._id=$options$$.id_qct);if($options$$.ngay_ct){let $start_date$$=moment($options$$.ngay_ct).startOf("date").toDate(),$end_date$$=moment($options$$.ngay_ct).endOf("date").toDate();
|
|
44
44
|
$condition_qct_qcts$$.$and.push({$or:[{tu_ngay:null},{tu_ngay:{$lte:$end_date$$}}]});$condition_qct_qcts$$.$and.push({$or:[{den_ngay:null},{den_ngay:{$gte:$start_date$$}}]})}$options$$.toObject&&($options$$=$options$$.toObject());$condition_qct_qcts$$=await dmqct.find($condition_qct_qcts$$).lean();const $keys$$=Object.keys($options$$),$qct$$=$condition_qct_qcts$$.find($qct$$=>{if($qct$$.dieu_kien&&0<$keys$$.length)try{let $str_func$$=$qct$$.dieu_kien;if(0<=$str_func$$.indexOf("async "))return!1;0!==
|
|
45
45
|
$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);return evalute($str_func$$,{...$options$$,master:{...$options$$},moment,numeral})}catch($e$$){return console.error("Error find quyen chung tu",$e$$,$qct$$.dieu_kien),!1}else return!0});counter.getNextSequence($id_app$$,$ma_ct$$,$qct$$?$qct$$._id.toString():$field$$,function($error$$,$rs$jscomp$0$$){if($error$$)console.error("auto create code for",$ma_ct$$,$field$$,$error$$),$callback$$($error$$);else{if($qct$$){let $tien_to$$=$qct$$.tien_to||
|
|
@@ -58,30 +58,30 @@ $body$jscomp$2_query$$[$k$$];else{let $item$$={};"number"==$ctrl$$.model.schema.
|
|
|
58
58
|
$or$$.length&&("$and"===$body$jscomp$2_query$$.cType?$condition$jscomp$1$$.$and=$or$$:$condition$jscomp$1$$.$or=$or$$);$shareRoute$$||0==$ctrl$$.require_id_app||($condition$jscomp$1$$.id_app=$req$$.user.current_id_app);$ctrl$$.finding?$ctrl$$.finding($req$$.user,$condition$jscomp$1$$,function($error$$,$condition$jscomp$0$$){setImmediate(()=>{if($error$$)return $res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$});$ctrl$$.dynamicFinding?$ctrl$$.dynamicFinding($req$$.user,$condition$jscomp$0$$,
|
|
59
59
|
function($e$$,$condition$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$req$$.condition=$condition$$;$next$$()}):($req$$.condition=$condition$jscomp$0$$,$next$$())})},{req:$req$$}):$ctrl$$.dynamicFinding?$ctrl$$.dynamicFinding($req$$.user,$condition$jscomp$1$$,function($e$$,$condition$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});
|
|
60
60
|
$req$$.condition=$condition$$;$next$$()}):($req$$.condition=$condition$jscomp$1$$,$next$$())})},function($req$$,$res$$,$next$$){if($shareRoute$$)return $next$$();permission.getRightByItem($req$$.user.current_id_app,$model$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $next$$($e$jscomp$0$$);if($admin$$)return $next$$();$req$$.admin=$admin$$;let $condition$$=$req$$.condition;$condition$$||($condition$$={});$condition$$.$and||($condition$$.$and=
|
|
61
|
-
[]);if($ctrl$$.options.onRightByItem)$ctrl$$.options.onRightByItem($req$$.user,$_condition$$,($e$$,$_condition$$)=>{setImmediate(()=>{if($e$$)return $next$$($e$$);_.isObject($_condition$$)&&0<Object.keys($_condition$$).length&&$condition$$.$and.push($_condition$$);$req$$.condition=$condition$$;$next$$()})});else _.isObject($_condition$$)&&0<Object.keys($_condition$$).length&&$condition$$.$and.push($_condition$$),$req$$.condition=$condition$$,$next$$()})},$ctrl$$.name)},
|
|
62
|
-
setImmediate(()=>{$ctrl$$.options.assignWiths?async.map($ctrl$$.options.assignWiths,($col$$,$callback$$)=>{setImmediate(()=>{let $m$$=global.getModel($col$$.ref_collection);permission.getRightByItem($req$$.user.current_id_app,$m$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);if($admin$$)return $callback$$();$_condition$$.id_app=$req$$.user.current_id_app
|
|
63
|
-
{if($e$$)return $callback$$($e$$);let $dsdt$$=underscore.pluck($rs$$,$col$$.ref_field);$dsdt$$.push("");$dsdt$$.push(null);$req$$.condition[$col$$.ref_field]={$in:$dsdt$$};$callback$$()})})})},$ctrl$$.name)})},$e$$=>{setImmediate(()=>{if($e$$)return $next$$($e$$);$next$$()})}):$next$$()})},function($req$$,$res$$,$next$$){if($shareRoute$$)return $next$$();setImmediate(()=>{if($req$$.admin||
|
|
64
|
-
"id_dt")){let $dmdt$$=mongoose.models.dmdt;permission.getRightDataView($req$$.user.current_id_app,$dmdt$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $next$$($e$jscomp$0$$);if($admin$$)return $next$$();$_condition$$.id_app=$req$$.user.current_id_app;$req$$.condition.ma_dt&&($_condition$$.ma_dt=$req$$.condition.ma_dt)
|
|
65
|
-
"ma_dt")){var $dsdt$jscomp$1_dsdt$$=underscore.pluck($rs$$,"ma_dt");$dsdt$jscomp$1_dsdt$$.push("");$dsdt$jscomp$1_dsdt$$.push(null);$dsdt$jscomp$1_dsdt$$.push(void 0);$req$$.condition.ma_dt={$in:$dsdt$jscomp$1_dsdt$$}}else $dsdt$jscomp$1_dsdt$$=underscore.pluck($rs$$,"_id"),$dsdt$jscomp$1_dsdt$$.push(""),$dsdt$jscomp$1_dsdt$$.push(null),$dsdt$jscomp$1_dsdt$$.push(void 0)
|
|
66
|
-
{if($shareRoute$$||$req$$.admin||"dmkho"===$ctrl$$.name)return $next$$();if(underscore.has($model$$.schema.paths,"ma_kho")||underscore.has($model$$.schema.paths,"ma_kho_x")||underscore.has($model$$.schema.paths,"ma_kho_n")){let $dmkho$$=mongoose.models.dmkho;permission.getRightDataView($req$$.user.current_id_app,$dmkho$$,$req$$.user.email,function($e$jscomp$0$$,$_condition
|
|
67
|
-
$req$$.user.current_id_app;$req$$.condition.ma_kho&&($_condition$$.ma_kho=$req$$.condition.ma_kho);$dmkho$$.find($_condition$$,{ma_kho:1}).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return $next$$($e$$);let $dskho$$=underscore.pluck($rs$$,"ma_kho");$dskho$$.push("");$dskho$$.push(null);$dskho$$.push(void 0);if(underscore.has($model$$.schema.paths,"ma_kho"))return $req$$.condition.ma_kho=
|
|
68
|
-
{$in:$dskho$$},$next$$();if("pnc"===$ctrl$$.name&&underscore.has($model$$.schema.paths,"ma_kho_n"))return $req$$.condition.ma_kho_n={$in:$dskho$$},$next$$();$next$$()})})})})}else $next$$()})},function($req$$,$res$$,$next$$){setImmediate(()=>{if($shareRoute$$)return $next$$();permission.hasRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.module,"view",function($error
|
|
69
|
-
$e$$=>{if($e$$)return $next$$($e$$);if(!$req$$.permission)return $res$$.send([]);$next$$()});else{if(!$permission$$)return $res$$.send([]);$next$$()}})},{notNeedRight:$ctrl$$.options.notNeedRight})})},async function($req$$,$res$$,$next$$){setImmediate(async()=>{let $condition$$=$req$$.condition;$condition$$||($condition$$={});if($shareRoute$$){$condition$$.shared=!0;var $id_sellers_query$$=
|
|
70
|
-
[]);$condition$$.$and.push({id_app:{$in:$id_sellers_query$$}});$condition$$.id_app&&$condition$$.$and.push({id_app:$condition$$.id_app})}else underscore.has($model$$.schema.paths,"id_app")&&!1!==$ctrl$$.require_id_app&&($condition$$.id_app=$req$$.user.current_id_app);underscore.extend($condition$$,$ctrl$$.keyValues);$condition$$.$and&&0===$condition$$.$and.length&&delete $condition$$.$and;$condition$$.$or&&
|
|
71
|
-
delete $condition$$.$nor;$id_sellers_query$$=null;if($req$$.query.count)$condition$$.$where?(console.log("phai loai bo $where trong condition"),$id_sellers_query$$=$model$$.count($condition$$,function($e$$,$data$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send({rows_number:$data$$})})):$id_sellers_query
|
|
72
|
-
$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send({rows_number:$data$$})});else{let $field_not_right$$;try{$field_not_right$$=await permission.getFieldNotRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.name)}catch($e$$){$field_not_right$$=[]}var $fields$$=$req$$.query.fields;let $gfields$$={};$fields$$&&(underscore.isArray($fields$$)?$fields$$.forEach($f$$=>
|
|
73
|
-
...$fields$$}:$fields$$.split(",").filter($f$$=>$f$$&&0>$field_not_right$$.indexOf($f$$)).forEach($f$$=>{"_id"!==$f$$&&($gfields$$[$f$$]=1)}));$field_not_right$$.forEach($f$$=>{$gfields$$[$f$$]=0});!$fields$$&&(($fields$$=$req$$.query.notfields)&&(underscore.isArray($fields$$)?$fields$$.forEach($f$$=>{$f$$&&"_id"!==$f$$&&($gfields$$[$f$$]=0)}):underscore.isObject($fields$$)?$gfields$$={...$gfields$$,...$fields$$}
|
|
74
|
-
"public"===$req$$.user.email)&&($gfields$$.dataview_to=0,$gfields$$.dataview_to_users=0);$condition$$.$text&&($gfields$$||($gfields$$={}),$gfields$$.textScore={$meta:"textScore"});if($req$$.query.group||$req$$.query.project||$req$$.query.match||$req$$.query.aggregate)try{$id_sellers_query$$=$model$$.aggregate([{$match:$condition$$}]);$req$$.query.group&&($group_page$$=JSON.parse($req$$.query.group),$id_sellers_query$$.group($group_page$$));
|
|
75
|
-
$id_sellers_query$$.match($match$$)}if($req$$.query.project)$limit_project$$=JSON.parse($req$$.query.project),$id_sellers_query$$.project($limit_project$$);else if($gfields$$&&0<Object.keys($gfields$$).length)$limit_project$$=$gfields$$;else if($limit_project$$={_id:1},$group_page$$)for(let $key$$ in $group_page$$)$limit_project$$[$key$$]=1;$id_sellers_query$$.project($limit_project$$);if($req$$.query.aggregate){let $aggregate$$=JSON.parse($req$$.query.aggregate)
|
|
76
|
-
$e$$.error||$e$$})}else console.log("search data",$ctrl$$.name,"shared",$shareRoute
|
|
77
|
-
$ctrl$$.name?20:1E5);$limit_project$$&&500<$limit_project$$&&"xlsx"!==$req$$.query.type_data&&!$req$$.query.print&&!1!==$ctrl$$.require_id_app&&"right"!==$ctrl$$.name&&($limit_project$$=500);$group_page$$?$id_sellers_query$$.skip((Number($group_page$$)-1)*$limit_project$$).limit($limit_project$$):$id_sellers_query$$.limit($limit_project$$);$id_sellers_query$$.lean&&($id_sellers_query
|
|
78
|
-
$condition$$),$res$$.status(400).send({error:$e$jscomp$0$$.error||$e$jscomp$0$$.message||$e$jscomp$0$$});$obj4view$$||($obj4view$$=[]);async.parallel({found:function($callback$$){$ctrl$$.found?$ctrl$$.found($req$$.user,$condition$$,$obj4view$$,function($error$$,$items$$){setImmediate(()=>{$callback$$($error$$,$items$$)})}):$callback$$(null,$obj4view$$)},set_collection_name:function($callback$$){$obj4view$$.forEach($obj$$=>
|
|
79
|
-
$callback$$(null)}},function($error$jscomp$0$$,$rs$jscomp$0$$){setImmediate(()=>{if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);$obj4view$$=$rs$jscomp$0$$.found;async.parallel({e_view:function($callback$$){$ctrl$$.onView($req$$.user,$obj4view$$,($error$$,$viewValue$$)=>{setImmediate(()=>{if($error$$)return console.error("Erron on view:",$error$$),$callback$$($error$$);$callback$$(null,$viewValue$$)})},{req:$req$$,
|
|
80
|
-
$_groupBy_func_string_rs$$){if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);if($req$$.query.type_data&&"xlsx"==$req$$.query.type_data){$app$jscomp$1_dir_root_template_e$$=(configs.paths||{}).templates;let $template_id$$,$excelTemplate$$;if($template_id$$=$req$$.query.id_template){if(!global.mongoose.Types.ObjectId.isValid($template_id$$))return $res$$.status(400).send({error:"M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i"})
|
|
81
|
-
if(!$excelTemplate$$||!$excelTemplate$$.file)return $res$$.status(400).send({error:"M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i"});var $_rs_msg_templatePath$$=$app$jscomp$1_dir_root_template_e$$?`${path.dirname($app$jscomp$1_dir_root_template_e$$)}${$excelTemplate$$.file}`:`${path.dirname(__dirname)}${$excelTemplate$$.file}`}else $app$jscomp$1_dir_root_template_e$$&&($_rs_msg_templatePath$$=`${$app$jscomp$1_dir_root_template_e$$}/excels/lists/${$ctrl$$.name}.xlsx`)
|
|
82
|
-
($_rs_msg_templatePath$$=`${path.dirname(__dirname)}/templates/excels/lists/${$ctrl$$.name}.xlsx`);if(!fs.existsSync($_rs_msg_templatePath$$))return $_rs_msg_templatePath$$="File m\u1eabu excel ch\u01b0a \u0111\u01b0\u1ee3c khai b\u00e1o t\u1ea1i '"+$_rs_msg_templatePath$$+"'",$res$$.status(400).send({error:$_rs_msg_templatePath$$});$app$jscomp$1_dir_root_template_e$$={};$_groupBy_func_string_rs$$.e_view.forEach($item$$=>{for(let $_key$$ in $item$$){let $_v
|
|
83
|
-
$_v$$[$__key$$];if(!underscore.isFunction($__v$$))if(0<=$__key$$.indexOf("ngay")||0<=$__key$$.indexOf("date"))try{$item$$[`${$_key$$}_${$__key$$}`]=new Date($__v$$)}catch($e$$){$item$$[`${$_key$$}_${$__key$$}`]=$__v$$}else $item$$[`${$_key$$}_${$__key$$}`]=$__v$$}else if($_v$$&&0<=$_key$$.indexOf("ngay")||0<=$_key$$.indexOf("date"))try{let $d$$=moment($_v$$,"YYYY-MM-DD");$d$$.isValid()&&($item$$[`${$_key$$}`]=$d$$.toDate()
|
|
84
|
-
$_v$$,$e$$)}}});$app$jscomp$1_dir_root_template_e$$.detail=$_groupBy_func_string_rs$$.e_view;if($excelTemplate$$&&$excelTemplate$$.handle_data){$_groupBy_func_string_rs$$=`return (async ()=>{
|
|
61
|
+
[]);if($ctrl$$.options.onRightByItem)$ctrl$$.options.onRightByItem($req$$.user,$_condition$$,($e$$,$_condition$$)=>{setImmediate(()=>{if($e$$)return $next$$($e$$);_.isObject($_condition$$)&&0<Object.keys($_condition$$).length&&$condition$$.$and.push($_condition$$);$req$$.condition=$condition$$;$next$$()})});else _.isObject($_condition$$)&&0<Object.keys($_condition$$).length&&$condition$$.$and.push($_condition$$),$req$$.condition=$condition$$,$next$$()})},$ctrl$$.name,{notNeedRight:$ctrl$$.options.notNeedRight})},
|
|
62
|
+
function($req$$,$res$$,$next$$){if($shareRoute$$)return $next$$();setImmediate(()=>{$ctrl$$.options.assignWiths?async.map($ctrl$$.options.assignWiths,($col$$,$callback$$)=>{setImmediate(()=>{let $m$$=global.getModel($col$$.ref_collection);permission.getRightByItem($req$$.user.current_id_app,$m$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);if($admin$$)return $callback$$();$_condition$$.id_app=$req$$.user.current_id_app;
|
|
63
|
+
$m$$.find($_condition$$).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return $callback$$($e$$);let $dsdt$$=underscore.pluck($rs$$,$col$$.ref_field);$dsdt$$.push("");$dsdt$$.push(null);$req$$.condition[$col$$.ref_field]={$in:$dsdt$$};$callback$$()})})})},$ctrl$$.name,{notNeedRight:$ctrl$$.options.notNeedRight})})},$e$$=>{setImmediate(()=>{if($e$$)return $next$$($e$$);$next$$()})}):$next$$()})},function($req$$,$res$$,$next$$){if($shareRoute$$)return $next$$();setImmediate(()=>{if($req$$.admin||
|
|
64
|
+
"dmdt"===$ctrl$$.name)return $next$$();if(underscore.has($model$$.schema.paths,"ma_dt")||underscore.has($model$$.schema.paths,"id_dt")){let $dmdt$$=mongoose.models.dmdt;permission.getRightDataView($req$$.user.current_id_app,$dmdt$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $next$$($e$jscomp$0$$);if($admin$$)return $next$$();$_condition$$.id_app=$req$$.user.current_id_app;$req$$.condition.ma_dt&&($_condition$$.ma_dt=$req$$.condition.ma_dt);
|
|
65
|
+
$dmdt$$.find($_condition$$,{ma_dt:1,_id:1}).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return $next$$($e$$);if(underscore.has($model$$.schema.paths,"ma_dt")){var $dsdt$jscomp$1_dsdt$$=underscore.pluck($rs$$,"ma_dt");$dsdt$jscomp$1_dsdt$$.push("");$dsdt$jscomp$1_dsdt$$.push(null);$dsdt$jscomp$1_dsdt$$.push(void 0);$req$$.condition.ma_dt={$in:$dsdt$jscomp$1_dsdt$$}}else $dsdt$jscomp$1_dsdt$$=underscore.pluck($rs$$,"_id"),$dsdt$jscomp$1_dsdt$$.push(""),$dsdt$jscomp$1_dsdt$$.push(null),$dsdt$jscomp$1_dsdt$$.push(void 0),
|
|
66
|
+
$req$$.condition.id_dt={$in:$dsdt$jscomp$1_dsdt$$};$next$$()})})})})}else $next$$()})},function($req$$,$res$$,$next$$){setImmediate(()=>{if($shareRoute$$||$req$$.admin||"dmkho"===$ctrl$$.name)return $next$$();if(underscore.has($model$$.schema.paths,"ma_kho")||underscore.has($model$$.schema.paths,"ma_kho_x")||underscore.has($model$$.schema.paths,"ma_kho_n")){let $dmkho$$=mongoose.models.dmkho;permission.getRightDataView($req$$.user.current_id_app,$dmkho$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,
|
|
67
|
+
$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $next$$($e$jscomp$0$$);if($admin$$)return $next$$();$_condition$$.id_app=$req$$.user.current_id_app;$req$$.condition.ma_kho&&($_condition$$.ma_kho=$req$$.condition.ma_kho);$dmkho$$.find($_condition$$,{ma_kho:1}).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return $next$$($e$$);let $dskho$$=underscore.pluck($rs$$,"ma_kho");$dskho$$.push("");$dskho$$.push(null);$dskho$$.push(void 0);if(underscore.has($model$$.schema.paths,"ma_kho"))return $req$$.condition.ma_kho=
|
|
68
|
+
{$in:$dskho$$},$next$$();if("pxc"===$ctrl$$.name&&underscore.has($model$$.schema.paths,"ma_kho_x"))return $req$$.condition.ma_kho_x={$in:$dskho$$},$next$$();if("pnc"===$ctrl$$.name&&underscore.has($model$$.schema.paths,"ma_kho_n"))return $req$$.condition.ma_kho_n={$in:$dskho$$},$next$$();$next$$()})})})})}else $next$$()})},function($req$$,$res$$,$next$$){setImmediate(()=>{if($shareRoute$$)return $next$$();permission.hasRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.module,"view",function($error$$,
|
|
69
|
+
$permission$$){setImmediate(()=>{if($ctrl$$.options.onQuery)$req$$.permission=$permission$$,$ctrl$$.options.onQuery($req$$,$e$$=>{if($e$$)return $next$$($e$$);if(!$req$$.permission)return $res$$.send([]);$next$$()});else{if(!$permission$$)return $res$$.send([]);$next$$()}})},{notNeedRight:$ctrl$$.options.notNeedRight})})},async function($req$$,$res$$,$next$$){setImmediate(async()=>{let $condition$$=$req$$.condition;$condition$$||($condition$$={});if($shareRoute$$){$condition$$.shared=!0;var $id_sellers_query$$=
|
|
70
|
+
(await app.find({sale_online:!0},{_id:1}).lean()).map($a$$=>$a$$._id);$condition$$.$and||($condition$$.$and=[]);$condition$$.$and.push({id_app:{$in:$id_sellers_query$$}});$condition$$.id_app&&$condition$$.$and.push({id_app:$condition$$.id_app})}else underscore.has($model$$.schema.paths,"id_app")&&!1!==$ctrl$$.require_id_app&&($condition$$.id_app=$req$$.user.current_id_app);underscore.extend($condition$$,$ctrl$$.keyValues);$condition$$.$and&&0===$condition$$.$and.length&&delete $condition$$.$and;$condition$$.$or&&
|
|
71
|
+
0===$condition$$.$or.length&&delete $condition$$.$or;$condition$$.$nor&&0===$condition$$.$nor.length&&delete $condition$$.$nor;$id_sellers_query$$=null;if($req$$.query.count)$condition$$.$where?(console.log("phai loai bo $where trong condition"),$id_sellers_query$$=$model$$.count($condition$$,function($e$$,$data$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send({rows_number:$data$$})})):$id_sellers_query$$=
|
|
72
|
+
$model$$.countDocuments($condition$$,function($e$$,$data$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send({rows_number:$data$$})});else{let $field_not_right$$;try{$field_not_right$$=await permission.getFieldNotRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.name)}catch($e$$){$field_not_right$$=[]}var $fields$$=$req$$.query.fields;let $gfields$$={};$fields$$&&(underscore.isArray($fields$$)?$fields$$.forEach($f$$=>
|
|
73
|
+
{"_id"!==$f$$&&($gfields$$[$f$$]=1)}):underscore.isObject($fields$$)?$gfields$$={...$gfields$$,...$fields$$}:$fields$$.split(",").filter($f$$=>$f$$&&0>$field_not_right$$.indexOf($f$$)).forEach($f$$=>{"_id"!==$f$$&&($gfields$$[$f$$]=1)}));$field_not_right$$.forEach($f$$=>{$gfields$$[$f$$]=0});!$fields$$&&(($fields$$=$req$$.query.notfields)&&(underscore.isArray($fields$$)?$fields$$.forEach($f$$=>{$f$$&&"_id"!==$f$$&&($gfields$$[$f$$]=0)}):underscore.isObject($fields$$)?$gfields$$={...$gfields$$,...$fields$$}:
|
|
74
|
+
$fields$$.split(",").forEach($f$$=>{$f$$&&"_id"!==$f$$&&($gfields$$[$f$$]=0)})),$shareRoute$$||"public"===$req$$.user.email)&&($gfields$$.dataview_to=0,$gfields$$.dataview_to_users=0);$condition$$.$text&&($gfields$$||($gfields$$={}),$gfields$$.textScore={$meta:"textScore"});if($req$$.query.group||$req$$.query.project||$req$$.query.match||$req$$.query.aggregate)try{$id_sellers_query$$=$model$$.aggregate([{$match:$condition$$}]);$req$$.query.group&&($group_page$$=JSON.parse($req$$.query.group),$id_sellers_query$$.group($group_page$$));
|
|
75
|
+
if($req$$.query.match){let $match$$=JSON.parse($req$$.query.match);$id_sellers_query$$.match($match$$)}if($req$$.query.project)$limit_project$$=JSON.parse($req$$.query.project),$id_sellers_query$$.project($limit_project$$);else if($gfields$$&&0<Object.keys($gfields$$).length)$limit_project$$=$gfields$$;else if($limit_project$$={_id:1},$group_page$$)for(let $key$$ in $group_page$$)$limit_project$$[$key$$]=1;$id_sellers_query$$.project($limit_project$$);if($req$$.query.aggregate){let $aggregate$$=JSON.parse($req$$.query.aggregate);
|
|
76
|
+
$id_sellers_query$$.append($aggregate$$)}}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$})}else console.log("search data",$ctrl$$.name,"shared",$shareRoute$$,JSON.stringify($condition$$)),$id_sellers_query$$=$model$$.find($condition$$,$gfields$$);!$sort$$&&$gfields$$.textScore?$sort$$={textScore:{$meta:"textScore"}}:$sort$$&&($sort$$._id=1);$sort$$&&$id_sellers_query$$.sort($sort$$);var $group_page$$=$req$$.query.page,$limit_project$$=$req$$.query.limit;$limit_project$$&&
|
|
77
|
+
($limit_project$$=Number($limit_project$$));$limit_project$$||($limit_project$$=!1!==$ctrl$$.require_id_app&&"right"!==$ctrl$$.name?20:1E5);$limit_project$$&&500<$limit_project$$&&"xlsx"!==$req$$.query.type_data&&!$req$$.query.print&&!1!==$ctrl$$.require_id_app&&"right"!==$ctrl$$.name&&($limit_project$$=500);$group_page$$?$id_sellers_query$$.skip((Number($group_page$$)-1)*$limit_project$$).limit($limit_project$$):$id_sellers_query$$.limit($limit_project$$);$id_sellers_query$$.lean&&($id_sellers_query$$=
|
|
78
|
+
$id_sellers_query$$.lean());$id_sellers_query$$.exec(function($e$jscomp$0$$,$obj4view$$){if($e$jscomp$0$$)return console.error($e$jscomp$0$$,$condition$$),$res$$.status(400).send({error:$e$jscomp$0$$.error||$e$jscomp$0$$.message||$e$jscomp$0$$});$obj4view$$||($obj4view$$=[]);async.parallel({found:function($callback$$){$ctrl$$.found?$ctrl$$.found($req$$.user,$condition$$,$obj4view$$,function($error$$,$items$$){setImmediate(()=>{$callback$$($error$$,$items$$)})}):$callback$$(null,$obj4view$$)},set_collection_name:function($callback$$){$obj4view$$.forEach($obj$$=>
|
|
79
|
+
{$obj$$.collection_name||($obj$$.collection_name=$ctrl$$.collection_name)});$callback$$(null)}},function($error$jscomp$0$$,$rs$jscomp$0$$){setImmediate(()=>{if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);$obj4view$$=$rs$jscomp$0$$.found;async.parallel({e_view:function($callback$$){$ctrl$$.onView($req$$.user,$obj4view$$,($error$$,$viewValue$$)=>{setImmediate(()=>{if($error$$)return console.error("Erron on view:",$error$$),$callback$$($error$$);$callback$$(null,$viewValue$$)})},{req:$req$$,
|
|
80
|
+
shareRoute:$shareRoute$$})}},async function($app$jscomp$1_dir_root_template_e$$,$_groupBy_func_string_rs$$){if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);if($req$$.query.type_data&&"xlsx"==$req$$.query.type_data){$app$jscomp$1_dir_root_template_e$$=(configs.paths||{}).templates;let $template_id$$,$excelTemplate$$;if($template_id$$=$req$$.query.id_template){if(!global.mongoose.Types.ObjectId.isValid($template_id$$))return $res$$.status(400).send({error:"M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i"});
|
|
81
|
+
$excelTemplate$$=await global.getModel("exportexceltemplate").findById($template_id$$);if(!$excelTemplate$$||!$excelTemplate$$.file)return $res$$.status(400).send({error:"M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i"});var $_rs_msg_templatePath$$=$app$jscomp$1_dir_root_template_e$$?`${path.dirname($app$jscomp$1_dir_root_template_e$$)}${$excelTemplate$$.file}`:`${path.dirname(__dirname)}${$excelTemplate$$.file}`}else $app$jscomp$1_dir_root_template_e$$&&($_rs_msg_templatePath$$=`${$app$jscomp$1_dir_root_template_e$$}/excels/lists/${$ctrl$$.name}.xlsx`),
|
|
82
|
+
$_rs_msg_templatePath$$&&fs.existsSync($_rs_msg_templatePath$$)||($_rs_msg_templatePath$$=`${path.dirname(__dirname)}/templates/excels/lists/${$ctrl$$.name}.xlsx`);if(!fs.existsSync($_rs_msg_templatePath$$))return $_rs_msg_templatePath$$="File m\u1eabu excel ch\u01b0a \u0111\u01b0\u1ee3c khai b\u00e1o t\u1ea1i '"+$_rs_msg_templatePath$$+"'",$res$$.status(400).send({error:$_rs_msg_templatePath$$});$app$jscomp$1_dir_root_template_e$$={};$_groupBy_func_string_rs$$.e_view.forEach($item$$=>{for(let $_key$$ in $item$$){let $_v$$=
|
|
83
|
+
$item$$[$_key$$];if(underscore.isObject($_v$$))for(let $__key$$ in $_v$$){let $__v$$=$_v$$[$__key$$];if(!underscore.isFunction($__v$$))if(0<=$__key$$.indexOf("ngay")||0<=$__key$$.indexOf("date"))try{$item$$[`${$_key$$}_${$__key$$}`]=new Date($__v$$)}catch($e$$){$item$$[`${$_key$$}_${$__key$$}`]=$__v$$}else $item$$[`${$_key$$}_${$__key$$}`]=$__v$$}else if($_v$$&&0<=$_key$$.indexOf("ngay")||0<=$_key$$.indexOf("date"))try{let $d$$=moment($_v$$,"YYYY-MM-DD");$d$$.isValid()&&($item$$[`${$_key$$}`]=$d$$.toDate(),
|
|
84
|
+
$item$$[`${$_key$$}_string`]=$d$$.format("DD/MM/YYYY"))}catch($e$$){console.error("Error convert to date",$_v$$,$e$$)}}});$app$jscomp$1_dir_root_template_e$$.detail=$_groupBy_func_string_rs$$.e_view;if($excelTemplate$$&&$excelTemplate$$.handle_data){$_groupBy_func_string_rs$$=`return (async ()=>{
|
|
85
85
|
${$excelTemplate$$.handle_data}
|
|
86
86
|
})`;try{$app$jscomp$1_dir_root_template_e$$=await evalute($_groupBy_func_string_rs$$,{data:$app$jscomp$1_dir_root_template_e$$,moment,numeral,_,utils})()}catch($e$$){return console.error($e$$,$_groupBy_func_string_rs$$),$res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$})}}excelReport($_rs_msg_templatePath$$,$app$jscomp$1_dir_root_template_e$$,function($e$$,$result$$){setImmediate(()=>{if($e$$)return console.error($e$$),$res$$.status(400).send({error:$e$$.message||$e$$.error||
|
|
87
87
|
$e$$});$res$$.setHeader("Content-Type","application/vnd.openxmlformats");$res$$.setHeader("Content-Disposition","attachment; filename="+$ctrl$$.name+".xlsx");$res$$.end($result$$,"binary")})})}else $req$$.query.print&&$req$$.query.id_rpt&&global.mongoose.Types.ObjectId.isValid($req$$.query.id_rpt)?htmlReport($req$$.query.id_rpt,{...$req$$.user.current_app_info,...$req$$.query,company:{...$req$$.user.current_app_info},detail:$_groupBy_func_string_rs$$.e_view,details:$_groupBy_func_string_rs$$.e_view}).then($rs$$=>
|
|
@@ -189,30 +189,32 @@ async function createIdRef($model$$,$data$$){$model$$=Object.values($model$$.sch
|
|
|
189
189
|
mongoose.models[$modelRef_modelRefName$$.toLowerCase()])?($localField_obj$$=await $modelRef_modelRefName$$.findOne({id_app:$data$$.id_app,[$foreignField$$]:$data$$[$localField_obj$$]}).lean(),$data$$[$namePath$$]=$localField_obj$$?$localField_obj$$._id.toString():null):$data$$[$namePath$$]=null:$data$$[$namePath$$]=null;$resove$$($path$$)})})))}catch($e2$$){return console.error("error create ref data",$e2$$),null}}
|
|
190
190
|
async function create($user$jscomp$0$$,$ctrl$$,$data$$,$callback$jscomp$1$$,$id_be_supply_by_user$$,$req$$){try{const $model$$=$ctrl$$.model,$voucher_options$$=(await OptionsModel.findOne({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name}).lean()||{}).option,$schema_paths$$=$model$$.schema.paths;let $v_data$$;try{$v_data$$=await asyncBodyToJson($data$$,$ctrl$$,$user$jscomp$0$$.current_id_app,$voucher_options$$)}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}underscore.has($schema_paths$$,
|
|
191
191
|
"ma_ct")&&$ctrl$$.options.isVoucher&&($v_data$$.ma_ct=$ctrl$$.name.toUpperCase());if($ctrl$$.options.requireRecaptchaToken){if(!$v_data$$["g-recaptcha-response"])return $callback$jscomp$1$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u g-recaptcha-response");try{await permission.verifyReCaptcha($v_data$$["g-recaptcha-response"])}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}}if(0>global.configs.admins.indexOf($user$jscomp$0$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;
|
|
192
|
-
$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($v_data$$,{action:"create",user:$user$jscomp$0$$}));if($requireOtp$$)try{await permission.verifyOTP($user$jscomp$0$$.email,$v_data$$["otp-id"],$v_data$$["otp-code"])}catch($e$$){return $callback$jscomp$1$$({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}
|
|
193
|
-
$
|
|
194
|
-
$
|
|
195
|
-
$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("
|
|
196
|
-
{$gte:$tu_ngay$$,$lte:$den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().exec(($e$jscomp$0$$,$rs$$)=>{setImmediate(()=>{if($rs$$){let $msgError$$="S\u1ed1 ch\u1ee9ng t\u1eeb "+$obj$jscomp$0$$.so_ct+
|
|
197
|
-
$callback$$()};let $File$$=global.getModel("file"),$Support$$=global.getModel("support");async.waterfall([function($callback$$){setImmediate(function(){permission.hasRight($obj$jscomp$0$$.id_app
|
|
198
|
-
$obj$jscomp$0$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$()},{data:$data$$}):$callback$$()})})},{data:$obj$jscomp$0$$,notNeedRight:$ctrl$$.options.notNeedRight})})}
|
|
199
|
-
let $_options_qct$$;$_options_qct$$=$obj
|
|
200
|
-
$qct$$.dieu_kien;0!==$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);return 0<$str_func$$.indexOf("async ")?!1:evalute($str_func$$,{...$_options_qct$$,master:{...$_options_qct$$},moment,numeral})}catch($e$$){return console.error("Error find quyen chung tu"
|
|
201
|
-
$ctrl$$.name,$field$$,function($e$$,$rs$$){if($e$$)return $cb$$();$obj
|
|
202
|
-
$count$$)},function($callback$$){getNextSequence($obj$jscomp$0$$.id_app,$ctrl$$.name,"so_ct",function($e$$,$rs$$){setImmediate(()=>{if($e$$)return $callback$$($e$$);$obj$jscomp$0$$.so_ct=$rs$$.so_ct;$checkVoucherNumber$$($error$$=>{$error$$?9<=$count$$?$callback$$($error$$):($count$$++,$callback$$()):($count$$=
|
|
203
|
-
"ma_dvcs")&&"dvcs"!==$ctrl$$.name)if($obj$jscomp$0$$.ma_dvcs)if(global.mongoose.Types.ObjectId.isValid($obj$jscomp$0$$.ma_dvcs)){let $_id_dvcs$$=global.mongoose.Types.ObjectId($obj$jscomp$0$$.ma_dvcs);await dvcs.findOne({_id:$_id_dvcs$$})?$callback$$():dvcs.create({_id:$_id_dvcs$$,ma_dvcs:"IMPORTED",
|
|
204
|
-
$rs$$){setImmediate(()=>{$rs$$&&($obj$jscomp$0$$.ma_dvcs=$rs$$._id.toString());$callback$$()})});else $callback$$()})},$callback$$=>{$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,$obj$jscomp$0$$,($e$jscomp$0
|
|
205
|
-
{if($error$$){let $msgError$$=$error$$;if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)});else $callback$$($msgError$$)}else{if($id_be_supply_by_user$$&&global.mongoose.Types.ObjectId.isValid($id_be_supply_by_user$$)){let $_id$$=
|
|
206
|
-
$ctrl$$.unique,$obj$jscomp$0$$,$ctrl$$.replaceIfExists,async($error$jscomp$1$$,$kq$$)=>{setImmediate(async()=>{if($error$jscomp$1$$||$kq$$){let $msgError$$=$error$jscomp$1$$||ERR_ALREADY_EXIST;console.error($msgError$$,$obj$jscomp$0$$);if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0
|
|
207
|
-
$ctrl$$.keyValues[$k$$];Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$jscomp$0$$[$model_path$$]&&underscore.isArray($obj$jscomp$0$$[$model_path$$])).forEach($model_path$$=>{$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&
|
|
208
|
-
$obj$jscomp$0$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>{$detail$$[$path$$]=$obj$jscomp$0$$[$path$$]})})});await createIdRef($model$$,$obj$jscomp$0$$);$ctrl$$.saving&&await $ctrl$$.saving($user$jscomp$0$$,$obj$jscomp$0$$);$ctrl$$.emit("saving",$obj$jscomp$0$$)
|
|
209
|
-
0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&console.error($e$$);$callback$$($msgErrors$$)});
|
|
210
|
-
$err$$,{_id:$obj_created$$._id.toString()})}),$ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgErrors$$=$msgErrors$$+"\n"+$e$$);$callback$$($msgErrors$$)});else $callback$$($msgErrors$$);
|
|
211
|
-
$req$$)}),$ctrl$$.emit("saved",$obj_created$$),$ctrl$$.emit("created",$obj_created$$),$obj_created$$=$obj_created$$.toObject(),runWebhooks($ctrl$$,$obj_created$$,"ADD",$voucher_options$$),$req$$&&pushNotification($ctrl$$,$obj_created$$,"new",null,null,{exclude_token:($req$$.query||
|
|
212
|
-
$obj_created$$)})},{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id.toString()})})})})})}})})})},function($obj$$,$callback$$){$ctrl$$.requestApprove($user$jscomp$0$$.current_app_info,$user$jscomp$0$$,$obj$$,$callback$$,$voucher_options$$)},function($obj$$,$callback$$){setImmediate(function(){$obj$$.collection_name
|
|
213
|
-
collection_link:$ctrl$$.collection_name}).lean().exec($e$$=>{$e$$&&console.error($e$$)})}),delete $obj$$.exfields.__files__);$obj$$.exfields&&$obj$$.exfields.__supports__&&($obj$$.exfields.__supports__.forEach($_file$$=>{$Support$$.findOneAndUpdate({_id:$_file$$._id},{id_link:$obj$$._id.toString(),collection_link:$ctrl$$.collection_name}).lean().exec($e$$=>
|
|
214
|
-
{if($error$$)return $callback$$($error$$);if($
|
|
215
|
-
$
|
|
192
|
+
$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($v_data$$,{action:"create",user:$user$jscomp$0$$}));if($requireOtp$$)try{await permission.verifyOTP($user$jscomp$0$$.email,$v_data$$["otp-id"],$v_data$$["otp-code"])}catch($e$$){return $callback$jscomp$1$$({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}if($ctrl$$.dynamicCreating)try{$v_data$$=await new Promise(($resolve$$,$reject$$)=>{try{$ctrl$$.dynamicCreating($user$jscomp$0$$,$v_data$$,function($error$$,$v_data$$){if($error$$)return $reject$$($error$$);
|
|
193
|
+
$resolve$$($v_data$$)})}catch($e$$){return $reject$$($e$$)}})}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}const $obj$jscomp$0$$=new $model$$;underscore.has($schema_paths$$,"exfields")&&($obj$jscomp$0$$.exfields=$v_data$$.exfields||{});for(let $f$$ in $v_data$$)underscore.has($schema_paths$$,$f$$)&&($obj$jscomp$0$$.set($f$$,$v_data$$[$f$$]),"exfields"!==$f$$||$obj$jscomp$0$$.exfields||($obj$jscomp$0$$.exfields={}));!0===underscore.has($schema_paths$$,"id_app")&&($obj$jscomp$0$$.id_app=
|
|
194
|
+
$user$jscomp$0$$.current_id_app);const $checkVoucherNumber$$=$callback$$=>{underscore.has($model$$.schema.paths,"ngay_ct")&&$obj$jscomp$0$$.ngay_ct?OptionsModel.findOne({id_app:$obj$jscomp$0$$.id_app,id_func:$ctrl$$.name},{option:1}).lean().exec(($e$jscomp$1$$,$rs$jscomp$0$$)=>{setImmediate(()=>{if($rs$jscomp$0$$&&$rs$jscomp$0$$.option&&$rs$jscomp$0$$.option.check_so_ct&&"0"!==$rs$jscomp$0$$.option.check_so_ct){let $query_check$$={id_app:$obj$jscomp$0$$.id_app,so_ct:$obj$jscomp$0$$.so_ct},$tu_ngay$$,
|
|
195
|
+
$den_ngay$$;switch($rs$jscomp$0$$.option.check_so_ct){case "1":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("day").toDate();$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("day").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "2":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("month").toDate();$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("month").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "3":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("quarter").toDate();
|
|
196
|
+
$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("quarter").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "8":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("year").toDate(),$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("year").toDate(),$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().exec(($e$jscomp$0$$,$rs$$)=>{setImmediate(()=>{if($rs$$){let $msgError$$="S\u1ed1 ch\u1ee9ng t\u1eeb "+$obj$jscomp$0$$.so_ct+
|
|
197
|
+
" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c";if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)});else $callback$$($msgError$$)}else $callback$$()})})}else $callback$$()})}):$callback$$()};let $File$$=global.getModel("file"),$Support$$=global.getModel("support");async.waterfall([function($callback$$){setImmediate(function(){permission.hasRight($obj$jscomp$0$$.id_app,
|
|
198
|
+
$user$jscomp$0$$.email,$ctrl$$.module,"add",function($error$jscomp$0$$,$hr$$,$c_app$$){setImmediate(()=>{if($error$jscomp$0$$||!$hr$$)return $callback$$($error$jscomp$0$$);$ctrl$$.checkData($c_app$$,$obj$jscomp$0$$,$e$$=>{if($e$$)return $callback$$($e$$);$ctrl$$.creating?$ctrl$$.creating($user$jscomp$0$$,$obj$jscomp$0$$,function($error$$,$obj$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)},{data:$data$$}):$callback$$(null,$obj$jscomp$0$$)})})},{data:$obj$jscomp$0$$,notNeedRight:$ctrl$$.options.notNeedRight})})},
|
|
199
|
+
($obj$$,$callback$$)=>{setImmediate(()=>{var $condition_qct$jscomp$1_ma_ct$$=$ctrl$$.name;$condition_qct$jscomp$1_ma_ct$$={status:!0,id_app:$obj$$.id_app,$and:[{$or:[{ma_ct:"#",ma_ct_khac:{$regex:$condition_qct$jscomp$1_ma_ct$$,$options:"i"}},{cac_ma_ct:$condition_qct$jscomp$1_ma_ct$$.toLowerCase()},{ma_ct:$condition_qct$jscomp$1_ma_ct$$.toUpperCase()}]}]};let $_options_qct$$;$_options_qct$$=$obj$$.toObject?$obj$$.toObject():{...$obj$$};let $keys_options$$=Object.keys($_options_qct$$);dmqct.find($condition_qct$jscomp$1_ma_ct$$).lean().exec(($e$jscomp$0$$,
|
|
200
|
+
$rs$jscomp$0$$)=>{setImmediate(()=>{let $qcts$$=($rs$jscomp$0$$||[]).filter($qct$$=>"so_ct"!==$qct$$.field&&!$obj$$[$qct$$.field]&&underscore.has($model$$.schema.paths,$qct$$.field));$qcts$$=$qcts$$.filter($qct$$=>{if($qct$$.dieu_kien&&0<$keys_options$$.length)try{let $str_func$$=$qct$$.dieu_kien;0!==$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);return 0<$str_func$$.indexOf("async ")?!1:evalute($str_func$$,{...$_options_qct$$,master:{...$_options_qct$$},moment,numeral})}catch($e$$){return console.error("Error find quyen chung tu",
|
|
201
|
+
$e$$.message,$qct$$.dieu_kien),!1}else return!0});async.map($qcts$$,($qct$$,$cb$$)=>{setImmediate(()=>{let $field$$=$qct$$.field,$_options$$={...$_options_qct$$};$_options$$.id_qct=$qct$$._id.toString();getNextSequence($obj$$.id_app,$ctrl$$.name,$field$$,function($e$$,$rs$$){if($e$$)return $cb$$();$obj$$[$field$$]=$rs$$[$field$$];$cb$$()},$_options$$)})},()=>{setImmediate(()=>{$callback$$()})})})})})},$callback$jscomp$0$$=>{setImmediate(function(){if(!0===underscore.has($model$$.schema.paths,"so_ct"))if($obj$jscomp$0$$.so_ct&&
|
|
202
|
+
$obj$jscomp$0$$.so_ct.toUpperCase()!==$ctrl$$.name.toUpperCase())$checkVoucherNumber$$($error$$=>{$callback$jscomp$0$$($error$$)});else{let $count$$=0;async.whilst(function($cb$$){$cb$$(null,10>$count$$)},function($callback$$){getNextSequence($obj$jscomp$0$$.id_app,$ctrl$$.name,"so_ct",function($e$$,$rs$$){setImmediate(()=>{if($e$$)return $callback$$($e$$);$obj$jscomp$0$$.so_ct=$rs$$.so_ct;$checkVoucherNumber$$($error$$=>{$error$$?9<=$count$$?$callback$$($error$$):($count$$++,$callback$$()):($count$$=
|
|
203
|
+
99999,$callback$$())})})},$obj$jscomp$0$$)},function($err$$){$callback$jscomp$0$$($err$$)})}else $callback$jscomp$0$$()})},function($callback$$){setImmediate(async()=>{if(underscore.has($model$$.schema.paths,"ma_dvcs")&&"dvcs"!==$ctrl$$.name)if($obj$jscomp$0$$.ma_dvcs)if(global.mongoose.Types.ObjectId.isValid($obj$jscomp$0$$.ma_dvcs)){let $_id_dvcs$$=global.mongoose.Types.ObjectId($obj$jscomp$0$$.ma_dvcs);await dvcs.findOne({_id:$_id_dvcs$$})?$callback$$():dvcs.create({_id:$_id_dvcs$$,ma_dvcs:"IMPORTED",
|
|
204
|
+
ten_dvcs:"Imported"},$e$$=>{setImmediate(()=>{$e$$&&console.error("Can't import dvcs",$e$$);$callback$$()})})}else $callback$$();else dvcs.findOne({id_app:$obj$jscomp$0$$.id_app,status:!0}).lean().exec(function($e$$,$rs$$){setImmediate(()=>{$rs$$&&($obj$jscomp$0$$.ma_dvcs=$rs$$._id.toString());$callback$$()})});else $callback$$()})},$callback$$=>{$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,$obj$jscomp$0$$,($e$jscomp$0$$,
|
|
205
|
+
$obj$$)=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);setImmediate(()=>{$obj$$.user_created=$user$jscomp$0$$.email;$obj$$.user_updated=$user$jscomp$0$$.email;validate($obj$$,async $error$$=>{setImmediate(async()=>{if($error$$){let $msgError$$=$error$$;if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)});else $callback$$($msgError$$)}else{if($id_be_supply_by_user$$&&global.mongoose.Types.ObjectId.isValid($id_be_supply_by_user$$)){let $_id$$=
|
|
206
|
+
global.mongoose.Types.ObjectId($id_be_supply_by_user$$);$obj$$._id=$_id$$;await $model$$.deleteOne({_id:$_id$$})}$callback$$()}})})})})},function($callback$$){setImmediate(function(){isExists($model$$,$ctrl$$.unique,$obj$jscomp$0$$,$ctrl$$.replaceIfExists,async($error$jscomp$1$$,$kq$$)=>{setImmediate(async()=>{if($error$jscomp$1$$||$kq$$){let $msgError$$=$error$jscomp$1$$||ERR_ALREADY_EXIST;console.error($msgError$$,$obj$jscomp$0$$);if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,
|
|
207
|
+
$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$({error:$msgError$$,code:ERR_ALREADY_EXIST_CODE})});else $callback$$({error:$msgError$$,code:ERR_ALREADY_EXIST_CODE})}else{for(let $k$$ in $ctrl$$.keyValues)$obj$jscomp$0$$[$k$$]=$ctrl$$.keyValues[$k$$];Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$jscomp$0$$[$model_path$$]&&underscore.isArray($obj$jscomp$0$$[$model_path$$])).forEach($model_path$$=>{$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&
|
|
208
|
+
Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>"line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&0<=fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$jscomp$0$$[$path$$]&&$obj$jscomp$0$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>{$detail$$[$path$$]=$obj$jscomp$0$$[$path$$]})})});await createIdRef($model$$,$obj$jscomp$0$$);$ctrl$$.saving&&await $ctrl$$.saving($user$jscomp$0$$,$obj$jscomp$0$$);$ctrl$$.emit("saving",$obj$jscomp$0$$);
|
|
209
|
+
$obj$jscomp$0$$.save(function($error$jscomp$0$$,$obj_created$$){setImmediate(()=>{if($error$jscomp$0$$){let $msgErrors$$=[];for(let $k$$ in $error$jscomp$0$$.errors)$msgErrors$$.push($error$jscomp$0$$.errors[$k$$].message);0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&console.error($e$$);$callback$$($msgErrors$$)});
|
|
210
|
+
else $callback$$($msgErrors$$)}else postData($obj_created$$,$ctrl$$,function($msgErrors$$){setImmediate(()=>{if($msgErrors$$)if($model$$.deleteOne({_id:$obj_created$$._id.toString()},$err$$=>{$err$$&&console.error("Error remove obj when has error post data:",$err$$,{_id:$obj_created$$._id.toString()})}),$ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgErrors$$=$msgErrors$$+"\n"+$e$$);$callback$$($msgErrors$$)});else $callback$$($msgErrors$$);
|
|
211
|
+
else if($req$$&&$req$$.header&&setImmediate(()=>{log.create({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name,action:"ADD",data:{id:$obj$jscomp$0$$._id.toString(),data:$obj$jscomp$0$$}},$user$jscomp$0$$.email,$req$$.header("user-agent"),$req$$)}),$ctrl$$.emit("saved",$obj_created$$),$ctrl$$.emit("created",$obj_created$$),$obj_created$$=$obj_created$$.toObject(),runWebhooks($ctrl$$,$obj_created$$,"ADD",$voucher_options$$),$req$$&&pushNotification($ctrl$$,$obj_created$$,"new",null,null,{exclude_token:($req$$.query||
|
|
212
|
+
{}).access_token}),$ctrl$$.cacheData($obj_created$$),$req$$&&!1!==($req$$.query||{}).return_data)$ctrl$$.onView($user$jscomp$0$$,[$obj_created$$],$error$$=>{setImmediate(()=>{if($error$$)return $callback$$($error$$);$callback$$(null,$obj_created$$)})},{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id.toString()})})})})})}})})})},function($obj$$,$callback$$){$ctrl$$.requestApprove($user$jscomp$0$$.current_app_info,$user$jscomp$0$$,$obj$$,$callback$$,$voucher_options$$)},function($obj$$,$callback$$){setImmediate(function(){$obj$$.collection_name=
|
|
213
|
+
$ctrl$$.collection_name;$obj$$.exfields&&$obj$$.exfields.__files__&&($obj$$.exfields.__files__.forEach($_file$$=>{$File$$.findOneAndUpdate({_id:$_file$$._id},{id_link:$obj$$._id.toString(),collection_link:$ctrl$$.collection_name}).lean().exec($e$$=>{$e$$&&console.error($e$$)})}),delete $obj$$.exfields.__files__);$obj$$.exfields&&$obj$$.exfields.__supports__&&($obj$$.exfields.__supports__.forEach($_file$$=>{$Support$$.findOneAndUpdate({_id:$_file$$._id},{id_link:$obj$$._id.toString(),collection_link:$ctrl$$.collection_name}).lean().exec($e$$=>
|
|
214
|
+
{console.error($e$$)})}),delete $obj$$.exfields.__supports__);if($ctrl$$.created)$ctrl$$.created($user$jscomp$0$$,$obj$$,function($error$jscomp$0$$,$rs$$){setImmediate(()=>{if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);if($ctrl$$.dynamicCreated)$ctrl$$.dynamicCreated($user$jscomp$0$$,$rs$$,function($error$$){if($error$$)return $callback$$($error$$);$req$$&&$req$$.uploadFile?($error$$="<html><title>OK</title><body>"+JSON.stringify($rs$$)+"</body></html>",$callback$$(null,$error$$)):$callback$$(null,
|
|
215
|
+
$rs$$)});else if($req$$&&$req$$.uploadFile){let $html$$="<html><title>OK</title><body>"+JSON.stringify($rs$$)+"</body></html>";$callback$$(null,$html$$)}else $callback$$(null,$rs$$)})});else if($ctrl$$.dynamicCreated)$ctrl$$.dynamicCreated($user$jscomp$0$$,$obj$$,function($error$jscomp$46_html$$){if($error$jscomp$46_html$$)return $callback$$($error$jscomp$46_html$$);$req$$&&$req$$.uploadFile?($error$jscomp$46_html$$="<html><title>OK</title><body>"+JSON.stringify($obj$$)+"</body></html>",$callback$$(null,
|
|
216
|
+
$error$jscomp$46_html$$)):$callback$$(null,$obj$$)});else if($req$$&&$req$$.uploadFile){let $html$$="<html><title>OK</title><body>"+JSON.stringify($obj$$)+"</body></html>";$callback$$(null,$html$$)}else $callback$$(null,$obj$$)})}],($e$jscomp$145_name_cached$$,$rs$$)=>{$e$jscomp$145_name_cached$$?(console.error($e$jscomp$145_name_cached$$),$callback$jscomp$1$$($e$jscomp$145_name_cached$$)):($e$jscomp$145_name_cached$$=$model$$.collection.name,$user$jscomp$0$$.current_id_app&&($e$jscomp$145_name_cached$$+=
|
|
217
|
+
$user$jscomp$0$$.current_id_app),delete global.cacheDatas[$e$jscomp$145_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),$callback$jscomp$1$$($e$$)}}
|
|
216
218
|
controller.prototype.create=function(){let $name$$=this.name,$ctrl$$=this;this.router.route(this.route_name).post(function($req$$,$res$$){let $session$$=$req$$.session;if(!0===$session$$["creating_"+$name$$])return $res$$.status(400).send({error:"\u0110ang x\u1eed l\u00fd d\u1eef li\u1ec7u"});$session$$["creating_"+$name$$]=!0;let $body$$=$req$$.body;if(!$body$$)return $res$$.status(411).send({error:"Kh\u00f4ng c\u00f3 n\u1ed9i dung c\u1ea7n l\u01b0u"});$req$$.files&&0<underscore.keys($req$$.files).length&&
|
|
217
219
|
("JSON"!=$body$$.return&&($req$$.uploadFile=!0),underscore.extend($body$$,$req$$.files));create($req$$.user,$ctrl$$,$body$$,($e$$,$rs$$)=>{setImmediate(()=>{$session$$["creating_"+$name$$]=!1;if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});!1===$req$$.query.return_data?$res$$.send({_id:$rs$$._id.toString()}):$res$$.send($rs$$)})},null,$req$$)})};
|
|
218
220
|
controller.prototype.quickCreate=function(){let $model$$=this.model,$name$$=this.name,$ctrl$$=this,$createFromTemplate$$=async($req$$,$res$$,$body$jscomp$4_query$$)=>{let $session$$=$req$$.session;if(!0===$session$$["creating_"+$name$$])return $res$$.status(400).send({error:"\u0110ang x\u1eed l\u00fd d\u1eef li\u1ec7u"});$session$$["creating_"+$name$$]=!0;if(!$body$jscomp$4_query$$){$body$jscomp$4_query$$=$req$$.params.template_code;if(!$body$jscomp$4_query$$)return $session$$["creating_"+$name$$]=
|
|
@@ -220,46 +222,49 @@ controller.prototype.quickCreate=function(){let $model$$=this.model,$name$$=this
|
|
|
220
222
|
{};delete $body$jscomp$4_query$$.so_ct;delete $body$jscomp$4_query$$.ngay_ct;delete $body$jscomp$4_query$$.user_created;delete $body$jscomp$4_query$$.date_created;delete $body$jscomp$4_query$$.user_updated;delete $body$jscomp$4_query$$.date_updated;delete $body$jscomp$4_query$$._id;delete $body$jscomp$4_query$$.pkey;delete $body$jscomp$4_query$$.__v;let $_data$$=$req$$.query;$req$$.body&&($_data$$=Object.assign($_data$$,$req$$.body));for(let $key$$ in $_data$$)$_data$$[$key$$]&&"access_token"!==$key$$&&
|
|
221
223
|
"token"!==$key$$&&"_id"!==$key$$&&(underscore.has($model$$.schema.paths,$key$$)&&($body$jscomp$4_query$$[$key$$]=$_data$$[$key$$]),$body$jscomp$4_query$$.details&&$body$jscomp$4_query$$.details.forEach($d$$=>{$d$$[$key$$]=$_data$$[$key$$]}));create($req$$.user,$ctrl$$,$body$jscomp$4_query$$,($e$$,$rs$$)=>{setImmediate(()=>{$session$$["creating_"+$name$$]=!1;if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)})},
|
|
222
224
|
null,$req$$)};this.router.route(`${this.route_name}/quickcreate/:template_code`).get(function($req$$,$res$$){$createFromTemplate$$($req$$,$res$$)});this.router.route(`${this.route_name}/quickcreate/:template_code`).post(function($req$$,$res$$){$createFromTemplate$$($req$$,$res$$)})};
|
|
223
|
-
const update=async function($user$jscomp$0$$,$ctrl$$,$id$$,$data$jscomp$
|
|
224
|
-
{}).option;let $current_obj$$;if($ctrl$$.options.requireRecaptchaToken){if(!$data$jscomp$
|
|
225
|
-
($requireOtp$$=$requireOtp$$($data$jscomp$
|
|
226
|
-
if(!$obj$$)return $callback$$("Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y");underscore.has($schema_paths$$,"exfields")&&($obj$$.exfields=$obj$$.exfields||{});const $old_obj$$=$obj$$.toObject();$current_obj$$=_.cloneDeep($old_obj$$);const $data_keys$$=Object.keys($data$jscomp$
|
|
227
|
-
$user$jscomp$0$$.email,$module$$,"update",function($error$$,$hr$$,$c_app$$){setImmediate(()=>{if($hr$$)$ctrl$$.checkData($c_app$$,{...$data$jscomp$
|
|
228
|
-
"so_ct")&&$obj$$.ngay_ct&&$data$jscomp$
|
|
225
|
+
const update=async function($user$jscomp$0$$,$ctrl$$,$id$$,$data$jscomp$1$$,$callback$jscomp$1$$,$action$jscomp$0$$,$req$$){delete $data$jscomp$1$$.__v;try{const $model$$=$ctrl$$.model,$unique$$=$ctrl$$.unique,$module$$=$ctrl$$.module,$schema_paths$$=$model$$.schema.paths;underscore.has($schema_paths$$,"ma_ct")&&$ctrl$$.options.isVoucher&&($data$jscomp$1$$.ma_ct=$ctrl$$.name.toUpperCase());const $voucher_options$$=(await OptionsModel.findOne({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name}).lean()||
|
|
226
|
+
{}).option;let $current_obj$$;if($ctrl$$.options.requireRecaptchaToken){if(!$data$jscomp$1$$["g-recaptcha-response"])return $callback$jscomp$1$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u g-recaptcha-response");try{await permission.verifyReCaptcha($data$jscomp$1$$["g-recaptcha-response"])}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}}if(0>global.configs.admins.indexOf($user$jscomp$0$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&
|
|
227
|
+
($requireOtp$$=$requireOtp$$($data$jscomp$1$$,{action:"update",_id:$id$$,user:$user$jscomp$0$$}));if($requireOtp$$)try{await permission.verifyOTP($user$jscomp$0$$.email,$data$jscomp$1$$["otp-id"],$data$jscomp$1$$["otp-code"])}catch($e$$){return $callback$jscomp$1$$({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}async.waterfall([function($callback$$){setImmediate(function(){$model$$.findOne({_id:$id$$}).exec(function($error$$,$obj$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);
|
|
228
|
+
if(!$obj$$)return $callback$$("Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y");underscore.has($schema_paths$$,"exfields")&&($obj$$.exfields=$obj$$.exfields||{});const $old_obj$$=$obj$$.toObject();$current_obj$$=_.cloneDeep($old_obj$$);const $data_keys$$=Object.keys($data$jscomp$1$$);for(let $key$$ in $old_obj$$)0>$data_keys$$.indexOf($key$$)&&($data$jscomp$1$$[$key$$]=$old_obj$$[$key$$]);$callback$$(null,$obj$$)})})})},function($obj$$,$callback$$){setImmediate(function(){permission.hasRight($user$jscomp$0$$.current_id_app,
|
|
229
|
+
$user$jscomp$0$$.email,$module$$,"update",function($error$$,$hr$$,$c_app$$){setImmediate(()=>{if($hr$$)$ctrl$$.checkData($c_app$$,{...$data$jscomp$1$$,_id:$obj$$._id.toString()},$e$$=>{if($e$$)return $callback$$($e$$);$callback$$(null,$obj$$)});else return $callback$$({error:$error$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})})},{data:$data$jscomp$1$$,obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})},function($obj$$,$callback$$){underscore.has($model$$.schema.paths,"ngay_ct")&&underscore.has($model$$.schema.paths,
|
|
230
|
+
"so_ct")&&$obj$$.ngay_ct&&$data$jscomp$1$$.so_ct&&$obj$$.so_ct!==$data$jscomp$1$$.so_ct?OptionsModel.findOne({id_app:$obj$$.id_app,id_func:$ctrl$$.name},{option:1}).lean().exec(($e$jscomp$0$$,$rs$jscomp$0$$)=>{setImmediate(()=>{if($rs$jscomp$0$$&&$rs$jscomp$0$$.option&&$rs$jscomp$0$$.option.check_so_ct&&"0"!==$rs$jscomp$0$$.option.check_so_ct){let $query_check$$={id_app:$obj$$.id_app,so_ct:$data$jscomp$1$$.so_ct,_id:{$ne:$obj$$._id.toString()}},$tu_ngay$$;var $date_check_den_ngay$$=$data$jscomp$1$$.ngay_ct||
|
|
229
231
|
$obj$$.ngay_ct;switch($rs$jscomp$0$$.option.check_so_ct){case "1":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("date").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("date").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "2":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("month").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("month").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};
|
|
230
232
|
break;case "3":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("quarter").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("quarter").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "8":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$date_check_den_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().exec(($e$$,
|
|
231
|
-
$rs$$)=>{setImmediate(()=>{if($rs$$)return $callback$$("S\u1ed1 ch\u1ee9ng t\u1eeb "+$data$jscomp$
|
|
232
|
-
$e$$)}setImmediate(function(){$ctrl$$.updating?$ctrl$$.updating($user$jscomp$0$$,$data$jscomp$
|
|
233
|
-
($
|
|
234
|
-
$
|
|
235
|
-
$
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
function($obj$$,$
|
|
239
|
-
{
|
|
240
|
-
|
|
241
|
-
{$
|
|
242
|
-
$
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}):setImmediate(()=>
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
{
|
|
249
|
-
($
|
|
250
|
-
|
|
251
|
-
$
|
|
233
|
+
$rs$$)=>{setImmediate(()=>{if($rs$$)return $callback$$("S\u1ed1 ch\u1ee9ng t\u1eeb "+$data$jscomp$1$$.so_ct+" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c");$callback$$(null,$obj$$)})})}else $callback$$(null,$obj$$)})}):$callback$$(null,$obj$$)},($obj$jscomp$2$$,$callback$jscomp$0$$)=>{(async($obj$jscomp$1$$,$callback$$)=>{try{(await permission.getFieldNotRight($obj$jscomp$1$$.id_app,$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $data$jscomp$1$$[$f$$]})}catch($e$$){console.error("Error get field not right",
|
|
234
|
+
$e$$)}setImmediate(function(){$ctrl$$.updating?$ctrl$$.updating($user$jscomp$0$$,$data$jscomp$1$$,$obj$jscomp$1$$,function($error$jscomp$0$$,$data$jscomp$0$$,$obj$jscomp$0$$){setImmediate(()=>{if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);$ctrl$$.dynamicUpdating?$ctrl$$.dynamicUpdating($user$jscomp$0$$,$data$jscomp$0$$,$obj$jscomp$0$$,function($error$$,$data$$,$obj$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)}):$callback$$(null,$obj$jscomp$0$$)})}):$ctrl$$.dynamicUpdating?
|
|
235
|
+
$ctrl$$.dynamicUpdating($req$$.user,$data$jscomp$1$$,$obj$jscomp$1$$,function($error$$,$data$$,$obj$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)}):$callback$$(null,$obj$jscomp$1$$)})})($obj$jscomp$2$$,$callback$jscomp$0$$)},function($obj$$,$callback$$){setImmediate(function(){if(!$unique$$||0===$unique$$.length)return $callback$$(null,$obj$$);let $c1$$={},$c2$$={};$obj$$.id_app&&($c1$$.id_app=$obj$$.id_app,$c2$$.id_app||($c2$$.id_app=$obj$$.id_app));$unique$$.forEach(function($key$$){$c1$$[$key$$]=
|
|
236
|
+
$obj$$[$key$$];$ctrl$$.model.schema.paths[$key$$]?("number"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=Number($data$jscomp$1$$[$key$$]):"date"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=new Date($data$jscomp$1$$[$key$$]):"string"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=($data$jscomp$1$$[$key$$]||"").toString():$c2$$[$key$$]=$data$jscomp$1$$[$key$$],$c2$$[$key$$]||($c2$$[$key$$]=$c1$$[$key$$])):console.error("field",
|
|
237
|
+
$key$$," is not exist. please check unique of controller")});!0!==underscore.isEqual($c1$$,$c2$$)?isExists($model$$,$unique$$,$c2$$,$ctrl$$.replaceIfExists,function($error$jscomp$0$$,$kq$$){setImmediate(()=>{if($error$jscomp$0$$||$kq$$){let $msgError$$=$error$jscomp$0$$||ERR_ALREADY_EXIST;console.error($msgError$$,$c2$$);if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);
|
|
238
|
+
else $callback$$($msgError$$)}else checkReference($model$$,$obj$$,function($error$$){setImmediate(()=>{if($error$$)return console.error("Keys arise data",$c1$$,$c2$$,$error$$),$callback$$({error:ERR_KEY_ARISE+($error$$.error||$error$$.message||$error$$),code:ERR_KEY_ARISE_CODE});$callback$$(null,$obj$$)})},$unique$$)})}):$callback$$(null,$obj$$)})},function($obj$$,$callback$$){let $keys$$=underscore.keys($model$$.referenceKeys).filter($key$$=>"_id"!==$key$$);$unique$$&&($keys$$=$keys$$.filter($key$$=>
|
|
239
|
+
0>$unique$$.indexOf($key$$).length));if(0===$keys$$.length)return $callback$$(null,$obj$$);checkReference($model$$,$obj$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$({error:ERR_ARISE+($msgError$$.error||$msgError$$.message||$msgError$$),code:ERR_ARISE_CODE});else $callback$$(null,$obj$$)})},
|
|
240
|
+
$keys$$)},function($obj$jscomp$1$$,$callback$$){$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,$obj$jscomp$1$$,($error$$,$obj$jscomp$0$$)=>{if($error$$)return $callback$$($error$$);setImmediate(function(){$data$jscomp$1$$.date_updated=new Date;$data$jscomp$1$$.user_updated=$user$jscomp$0$$.email;delete $data$jscomp$1$$.__v;$ctrl$$.options.onUpdateExtending||($ctrl$$.options.onUpdateExtending=function($obj$$,$data$$,$action$$,
|
|
241
|
+
$fn$$){$fn$$()});$ctrl$$.options.onUpdateExtending($obj$jscomp$0$$,$data$jscomp$1$$,$action$jscomp$0$$,function(){underscore.has($schema_paths$$,"exfields")&&$data$jscomp$1$$.exfields&&($obj$jscomp$0$$.exfields=$data$jscomp$1$$.exfields);for(let $f$$ in $data$jscomp$1$$)underscore.has($schema_paths$$,$f$$)&&($obj$jscomp$0$$.set($f$$,$data$jscomp$1$$[$f$$]),"exfields"!==$f$$||$obj$jscomp$0$$.exfields||($obj$jscomp$0$$.exfields={}));validate($obj$jscomp$0$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,
|
|
242
|
+
$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$);else $callback$$(null,$obj$jscomp$0$$)})})})})})},function($obj$$,$callback$$){setImmediate(async()=>{$obj$$.ngay_ct&&($obj$$.ngay_ct=moment($obj$$.ngay_ct).toDate());for(var $$condition_k$$ in $ctrl$$.keyValues)$obj$$[$$condition_k$$]=$ctrl$$.keyValues[$$condition_k$$];Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$$[$model_path$$]&&underscore.isArray($obj$$[$model_path$$])).forEach($model_path$$=>
|
|
243
|
+
{$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>"line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$$[$path$$]&&$obj$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>{$detail$$[$path$$]=$obj$$[$path$$]})})});await createIdRef($model$$,$obj$$);$ctrl$$.saving&&await $ctrl$$.saving($user$jscomp$0$$,
|
|
244
|
+
$obj$$);$ctrl$$.emit("saving",$obj$$);let $obj_created$$,$error$jscomp$0$$;$data$jscomp$1$$.$condition&&($$condition_k$$=$data$jscomp$1$$.$condition,$$condition_k$$._id=$obj$$._id,await $model$$.findOne($$condition_k$$)||($error$jscomp$0$$=ERR_CAN_NOT_UPDATE),delete $data$jscomp$1$$.$condition);if(!$error$jscomp$0$$)try{$obj_created$$=await $obj$$.save()}catch($e$$){$error$jscomp$0$$=$e$$}if($error$jscomp$0$$){let $msgErrors$$=[];for(let $k$$ in $error$jscomp$0$$.errors)$msgErrors$$.push($error$jscomp$0$$.errors[$k$$].message);
|
|
245
|
+
0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&console.error("onErrorUpdating",$e$$);$callback$$({error:$msgErrors$$,code:ERR_CAN_NOT_UPDATE_CODE})},$current_obj$$);else $callback$$({error:$msgErrors$$,code:ERR_CAN_NOT_UPDATE_CODE})}else $req$$&&$req$$.header&&setImmediate(()=>{log.create({id_app:$user$jscomp$0$$.current_id_app,
|
|
246
|
+
id_func:$ctrl$$.name,action:"UPDATE",data:{oldData:$current_obj$$,newData:$data$jscomp$1$$,id:$obj$$._id.toString()}},$user$jscomp$0$$.email,$req$$.header("user-agent"),$req$$)}),postData($obj_created$$,$ctrl$$,function($msgError$$){$msgError$$?setImmediate(()=>{$current_obj$$&&$model$$.findByIdAndUpdate($current_obj$$._id,{$set:$current_obj$$},function($err$$,$restore_data$$){if($err$$||!$restore_data$$)return console.error("can't restore voucher",$err$$||": don't find voucher");console.log("restored data of voucher. posting...");
|
|
247
|
+
$model$$.findById($current_obj$$._id,($e$jscomp$0$$,$_d$$)=>{if(!$_d$$)return console.error("Don't find voucher",$current_obj$$._id);postData($_d$$,$ctrl$$,function($e$$){if($e$$)return console.error("can't repost voucher",$e$$);console.log("reposted voucher",$_d$$._id)})})});if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}):setImmediate(()=>
|
|
248
|
+
{$ctrl$$.emit("saved",$obj_created$$);$ctrl$$.emit("updated",$obj_created$$);$obj_created$$=$obj_created$$.toObject();runWebhooks($ctrl$$,$obj_created$$,"UPDATE",$voucher_options$$);$req$$&&pushNotification($ctrl$$,$obj_created$$,"update",$current_obj$$,null,{exclude_token:$req$$.query.access_token});$ctrl$$.cacheData($obj_created$$);if($req$$&&!1!==$req$$.query.return_data)$ctrl$$.onView($user$jscomp$0$$,[$obj_created$$],function($error$$,$viewValue$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);
|
|
249
|
+
$callback$$(null,$viewValue$$[0])})},{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id})})})})},function($obj$$,$callback$$){$ctrl$$.requestApprove($user$jscomp$0$$.current_app_info,$user$jscomp$0$$,$obj$$,$callback$$,$voucher_options$$)},function($obj$jscomp$0$$,$callback$$){void 0!=$obj$jscomp$0$$.trang_thai&&setImmediate(async()=>{Approve.findOne({id_ct:$obj$jscomp$0$$._id.toString(),"update_after_approve.data.trang_thai":$obj$jscomp$0$$.trang_thai.toString()}).lean().exec(($e$$,$rs$$)=>
|
|
250
|
+
{!$rs$$||$rs$$.user_approved||$rs$$.user_denied||($rs$$.user_approved=$req$$.user.email,$rs$$.user_approved_name=$req$$.user.name,$rs$$.date_approved=new Date,Approve.updateOne({_id:$rs$$._id},$rs$$).then(()=>{Approve.sendNotifyApproved($rs$$,$req$$.query.access_token)}))})});setImmediate(async()=>{(await permission.getFieldNotRight($obj$jscomp$0$$.id_app,$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $obj$jscomp$0$$[$f$$]});$obj$jscomp$0$$.collection_name=$ctrl$$.collection_name;$ctrl$$.updated?
|
|
251
|
+
$ctrl$$.updated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$jscomp$0$$,$obj$$){if($error$jscomp$0$$)return console.error("error when saved",$error$jscomp$0$$),$callback$$($error$jscomp$0$$);$ctrl$$.dynamicUpdated?$ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)}):$callback$$(null,$obj$$)},$current_obj$$):$ctrl$$.dynamicUpdated?$ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$$){if($error$$)return $callback$$($error$$);
|
|
252
|
+
$callback$$(null,$obj$jscomp$0$$)}):$callback$$(null,$obj$jscomp$0$$)})}],($e$jscomp$164_name_cached$$,$rs$$)=>{$e$jscomp$164_name_cached$$?(console.error($e$jscomp$164_name_cached$$),$callback$jscomp$1$$($e$jscomp$164_name_cached$$)):($e$jscomp$164_name_cached$$=$model$$.collection.name,$user$jscomp$0$$.current_id_app&&($e$jscomp$164_name_cached$$+=$user$jscomp$0$$.current_id_app),delete global.cacheDatas[$e$jscomp$164_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),
|
|
253
|
+
$callback$jscomp$1$$($e$$)}};
|
|
254
|
+
controller.prototype.update=function(){let $ctrl$$=this,$name$$=this.name;this.router.route(this.route_name+"/:id").put(function($req$$,$res$$){let $session$$=$req$$.session;if(!0===$session$$["updating_"+$name$$])return $res$$.status(400).send({error:"\u0110ang x\u1eed l\u00fd d\u1eef li\u1ec7u"});$session$$["updating_"+$name$$]=!0;let $body$$=$req$$.body;$req$$.files&&underscore.extend($body$$,$req$$.files);let $data$$;try{$data$$=bodyToJson($body$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||
|
|
255
|
+
$e$$})}update($req$$.user,$ctrl$$,$req$$.params.id,$data$$,($e$$,$rs$$)=>{setImmediate(()=>{$session$$["updating_"+$name$$]=!1;if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});!1===$req$$.query.return_data?$res$$.send({_id:$rs$$._id.toString()}):$res$$.send($rs$$)})},null,$req$$)})};
|
|
252
256
|
function checkReference($model$jscomp$0$$,$obj$$,$fn$$,$keys$$){$model$jscomp$0$$.referenceKeys?($keys$$||($keys$$=underscore.keys($model$jscomp$0$$.referenceKeys)),async.map($keys$$,function($key$$,$callback$$){setImmediate(()=>{let $ref$$=$model$jscomp$0$$.referenceKeys[$key$$];if(!$ref$$)return $callback$$();let $value$$=$obj$$[$key$$];"_id"===$key$$&&($value$$=$value$$.toString());if(void 0==$value$$||null==$value$$||""==$value$$)return $callback$$();async.map($ref$$,function($r$$,$cb$$){setImmediate(()=>
|
|
253
257
|
{let $model$$=mongoose.models[$r$$.model];if($model$$){let $query$$={id_app:$obj$$.id_app};var $_w_k$$=$r$$.key;$_w_k$$&&($query$$[$_w_k$$]=$value$$);$r$$.where&&(underscore.isObject($r$$.where)&&($query$$=Object.assign($query$$,$r$$.where)),underscore.isFunction($r$$.where)&&($_w_k$$=$r$$.where($obj$$),$query$$=Object.assign($query$$,$_w_k$$)));$model$$.find($query$$).limit(1).lean().exec(function($error$$,$o$$){setImmediate(()=>{if($error$$)return $cb$$($error$$);if($o$$&&0<$o$$.length){let $msgError$$;
|
|
254
258
|
$msgError$$=$r$$.error?(new Function("obj","return `"+$r$$.error.replace("{{VALUE}}",$value$$)+"`"))($obj$$):ERR_DATA_GENERATED;return $cb$$({error:$msgError$$,code:ERR_DATA_GENERATED_CODE})}$cb$$()})})}else $cb$$()})},function($e$$){if($e$$)return $callback$$($e$$);$callback$$()})})},$error$$=>{$fn$$($error$$)})):$fn$$()}
|
|
255
|
-
controller.prototype.delete=function(){let $model$$=this.model,$ctrl$$=this,$module$$=this.module,$codeSync$$=this.codeSync,$keySync$$=this.keySync;this.router.route(this.route_name+"/:id").delete(function($req$$,$res$$,$next$$){if(!global.mongoose.Types.ObjectId.isValid($req$$.params.id))return $res$$.status(400).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$model$$.findOne({_id:$req$$.params.id}).lean().exec(async function($e$jscomp$
|
|
256
|
-
$e$jscomp$
|
|
257
|
-
_id:$req$$.params.id,user:$e$jscomp$
|
|
258
|
-
($error$$.error||$error$$.message||$error$$),code:ERR_ARISE_CODE});$req$$.obj=$obj$$;$next$$()});else return $res$$.status(403).send({error:$error$jscomp$0$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})},{obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})})},function($req$$,$res$$,$next$$){setImmediate(()=>{let $obj$jscomp$
|
|
259
|
-
$res$$.status(400).send({error:$e$$.message||$e$$});$req$$.obj=$obj$$;$next$$()}
|
|
260
|
-
setImmediate(()=>{$
|
|
261
|
-
|
|
262
|
-
{
|
|
259
|
+
controller.prototype.delete=function(){let $model$$=this.model,$ctrl$$=this,$module$$=this.module,$codeSync$$=this.codeSync,$keySync$$=this.keySync;this.router.route(this.route_name+"/:id").delete(function($req$$,$res$$,$next$$){if(!global.mongoose.Types.ObjectId.isValid($req$$.params.id))return $res$$.status(400).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$model$$.findOne({_id:$req$$.params.id}).lean().exec(async function($e$jscomp$169_user$$,$obj$$){if($e$jscomp$169_user$$)return console.error($e$jscomp$169_user$$),
|
|
260
|
+
$e$jscomp$169_user$$.error?$res$$.status(400).send($e$jscomp$169_user$$):$res$$.status(400).send({error:$e$jscomp$169_user$$.message||$e$jscomp$169_user$$.error||$e$jscomp$169_user$$});if(!$obj$$)return $res$$.status(404).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$e$jscomp$169_user$$=$req$$.user;if(0>global.configs.admins.indexOf($e$jscomp$169_user$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($obj$$,{action:"delete",
|
|
261
|
+
_id:$req$$.params.id,user:$e$jscomp$169_user$$}));if($requireOtp$$)try{await permission.verifyOTP($e$jscomp$169_user$$.email,$req$$.query["otp-id"],$req$$.query["otp-code"])}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}setImmediate(()=>{permission.hasRight($obj$$.id_app,$req$$.user.email,$module$$,"delete",function($error$jscomp$0$$,$hr$$){if($hr$$)checkReference($model$$,$obj$$,function($error$$){if($error$$)return $res$$.status(400).send({error:ERR_ARISE+
|
|
262
|
+
($error$$.error||$error$$.message||$error$$),code:ERR_ARISE_CODE});$req$$.obj=$obj$$;$next$$()});else return $res$$.status(403).send({error:$error$jscomp$0$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})},{obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})})},function($req$$,$res$$,$next$$){setImmediate(()=>{let $obj$jscomp$1$$=$req$$.obj;$ctrl$$.deleting?$ctrl$$.deleting($req$$.user,$obj$jscomp$1$$,function($e$$,$obj$jscomp$0$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):
|
|
263
|
+
$res$$.status(400).send({error:$e$$.message||$e$$});$ctrl$$.dynamicDeleting?$ctrl$$.dynamicDeleting($req$$.user,$obj$jscomp$0$$,function($error$$,$obj$$){if($error$$)return $next$$($error$$);$req$$.obj=$obj$$;$next$$()}):($req$$.obj=$obj$jscomp$0$$,$next$$())},{req:$req$$}):$ctrl$$.dynamicDeleting?$ctrl$$.dynamicDeleting($req$$.user,$obj$jscomp$1$$,function($error$$,$obj$$){if($error$$)return $next$$($error$$);$req$$.obj=$obj$$;$next$$()}):($req$$.obj=$obj$jscomp$1$$,$next$$())})},function($req$$,
|
|
264
|
+
$res$$){setImmediate(()=>{let $obj$jscomp$0$$=$req$$.obj;$ctrl$$.emit("deleting",{...$obj$jscomp$0$$});$model$$.deleteOne({_id:$obj$jscomp$0$$._id},function($e$jscomp$1$$){if($e$jscomp$1$$)return console.error($e$jscomp$1$$),$e$jscomp$1$$.error?$res$$.status(400).send($e$jscomp$1$$):$res$$.status(400).send({error:$e$jscomp$1$$.message||$e$jscomp$1$$});setImmediate(()=>{$ctrl$$.deleteData({...$obj$jscomp$0$$});log.create({id_app:$req$$.user.current_id_app,id_func:$ctrl$$.name,action:"DELETE",data:{id:$obj$jscomp$0$$._id,
|
|
265
|
+
data:$obj$jscomp$0$$}},$req$$.user.email,$req$$.header("user-agent"),$req$$);link.deleteMany({$or:[{id_a:$obj$jscomp$0$$._id},{id_b:$obj$jscomp$0$$._id}]},function($e$$){$e$$&&console.error("Can't delete links\n"+$e$$)})});setImmediate(()=>{$ctrl$$.emit("deleted",$obj$jscomp$0$$);runWebhooks($ctrl$$,$obj$jscomp$0$$,"DELETE")});pushNotification($ctrl$$,$obj$jscomp$0$$,"delete",null,null,{exclude_token:$req$$.query.access_token});setImmediate(()=>{deletePost($req$$.user,$obj$jscomp$0$$,async $e$jscomp$0$$=>
|
|
266
|
+
{if($e$jscomp$0$$)return console.error($e$jscomp$0$$),$e$jscomp$0$$.error?$res$$.status(400).send($e$jscomp$0$$):$res$$.status(400).send({error:$e$jscomp$0$$.message||$e$jscomp$0$$});if($ctrl$$.dynamicDeletePost)try{await $ctrl$$.dynamicDeletePost($obj$jscomp$0$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$})}setImmediate(()=>{$ctrl$$.deleted?$ctrl$$.deleted($req$$.user,$obj$jscomp$0$$,function($e$$,$obj$$){setImmediate(()=>{if($e$$)return console.error($e$$),
|
|
267
|
+
$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($obj$$)})}):$res$$.send($obj$jscomp$0$$)})},$codeSync$$,$keySync$$)})})})})};
|
|
263
268
|
controller.prototype.history=function(){let $name$$=this.name;this.router.route(this.route_name+"/g/history/:id").get(function($actions_req$$,$res$$){let $query$$={id_func:$name$$,id_app:$actions_req$$.user.current_id_app,"data.id":$actions_req$$.params.id};($actions_req$$=$actions_req$$.query.actions)?($actions_req$$=$actions_req$$.split(","),$query$$.action={$in:$actions_req$$,$ne:"GET"}):$query$$.action={$ne:"GET"};log.find($query$$).lean().exec(function($e$$,$rs$$){setImmediate(()=>$e$$?(console.error($e$$),
|
|
264
269
|
$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})):$res$$.send($rs$$))})})};
|
|
265
270
|
controller.prototype.logs=function(){let $ctrl$$=this,$name$$=this.name;this.router.route(this.route_name+"/g/log/:action").get(function($req$$,$res$$){var $action$jscomp$3_den_ngay$$=$req$$.params.action.toUpperCase();let $query$$={id_func:$name$$,id_app:$req$$.user.current_id_app};"ALL"!==$action$jscomp$3_den_ngay$$&&($query$$.action=$action$jscomp$3_den_ngay$$);if($req$$.query.tu_ngay){var $date_created_tu_ngay$$=moment(new Date($req$$.query.tu_ngay)).startOf("date").toDate();$date_created_tu_ngay$$=
|
|
@@ -29,15 +29,15 @@ $rptConfig$$.handle_data_expression.indexOf("async "))return $res$$.status(400).
|
|
|
29
29
|
})`;try{($func_string$jscomp$3_rptInfo$jscomp$2_rs$$=await evalute($func_string$jscomp$2_key$$,{data:$app$$,moment,user:$req$jscomp$0$$.user,utils,numeral,getData:getParameterData})())&&($app$$=$func_string$jscomp$3_rptInfo$jscomp$2_rs$$)}catch($e$$){return console.error($e$$,$func_string$jscomp$2_key$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})}}var $func_string$jscomp$3_rptInfo$jscomp$2_rs$$=await reportinfo.findOne({code:($req$jscomp$0$$.query.report_info_code||
|
|
30
30
|
$rptId$$).toLowerCase()}).lean();if($func_string$jscomp$3_rptInfo$jscomp$2_rs$$&&$func_string$jscomp$3_rptInfo$jscomp$2_rs$$.handle_data_expression){if(0<=$func_string$jscomp$3_rptInfo$jscomp$2_rs$$.handle_data_expression.indexOf("async "))return $res$$.status(400).send({error:"async function is not allow"});$func_string$jscomp$3_rptInfo$jscomp$2_rs$$=`return (async ()=>{
|
|
31
31
|
${$func_string$jscomp$3_rptInfo$jscomp$2_rs$$.handle_data_expression}
|
|
32
|
-
})`;try{const $rs$$=await evalute($func_string$jscomp$3_rptInfo$jscomp$2_rs$$,{data:$data$jscomp$3_e$$,moment,user:$req$jscomp$0$$.user,utils,numeral,getData:getParameterData})();$rs$$&&($app$$.detail=$app$$.details=$rs$$)}catch($e$$){return console.error($e$$,$func_string$jscomp$3_rptInfo$jscomp$2_rs$$),$res$$.status(400).send({error:$e$$.message||$e$$})}}$
|
|
33
|
-
else $options$$.onExport($app$$,function(){setImmediate(()=>{if($req$jscomp$0$$.query.print)htmlReport($html_template$$,$app$$).then($rs$$=>$res$$.send($rs$$)
|
|
34
|
-
$error$$})
|
|
35
|
-
$res$$.setHeader("Content-Disposition","attachment; filename="+$rptId$$+".docx"),$res$$.write($result$$,"binary"),$res$$.end(null,"binary"))
|
|
36
|
-
$
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
!fs.existsSync($templatePath$$))return $reject$$("M\u1eabu
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)},$res$$):$res$$.status(403).send({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xem b\u00e1o c\u00e1o n\u00e0y"})},
|
|
43
|
-
"PUT"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).put($r$$):this.router.route(`${this.base_path+this.module}/${$routeName$$}`).get($r$$)}}module.exports=controllerRPT;
|
|
32
|
+
})`;try{const $rs$$=await evalute($func_string$jscomp$3_rptInfo$jscomp$2_rs$$,{data:$data$jscomp$3_e$$,moment,user:$req$jscomp$0$$.user,utils,numeral,getData:getParameterData})();$rs$$&&($app$$.detail=$app$$.details=$rs$$)}catch($e$$){return console.error($e$$,$func_string$jscomp$3_rptInfo$jscomp$2_rs$$),$res$$.status(400).send({error:$e$$.message||$e$$})}}else $app$$.detail.forEach($r$$=>{for(let $_key$$ in $r$$){let $_v$$=$r$$[$_key$$];if($_v$$&&0<=$_key$$.indexOf("ngay")||0<=$_key$$.indexOf("date"))try{let $d$$=
|
|
33
|
+
moment($_v$$,"YYYY-MM-DD");$d$$.isValid()&&($r$$[`${$_key$$}`]=$d$$.toDate(),$r$$[`${$_key$$}_string`]=$d$$.format("DD/MM/YYYY"))}catch($e$$){console.error("Error convert to date",$_v$$,$e$$)}}});$rptConfig$$&&$rptConfig$$.parameters&&await prepareParameters($rptConfig$$.parameters,$app$$,$app$$);if($req$jscomp$0$$.query.json)$res$$.json($app$$);else $options$$.onExport($app$$,function(){setImmediate(()=>{if($req$jscomp$0$$.query.print)htmlReport($html_template$$,$app$$).then($rs$$=>$res$$.send($rs$$),
|
|
34
|
+
$error$$=>{$res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$})});else{let $ext$$=$templatePath$$.split(".").pop();"xlsx"===$ext$$?excelReport($templatePath$$,$app$$,function($error$$,$result$$){if($error$$)return console.error("Error export to excel",$error$$),$res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$});$res$$.setHeader("Content-Type","application/vnd.openxmlformats");$res$$.setHeader("Content-Disposition","attachment; filename="+$rptId$$+".xlsx");
|
|
35
|
+
$res$$.end($result$$,"binary")}):textReport($templatePath$$,$app$$,function($error$$,$result$$){if($error$$)return console.error("Error export to text",$error$$),$res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$});"docx"===$ext$$?($res$$.setHeader("Content-Type","application/vnd.openxmlformats-officedocument.wordprocessingml.document"),$res$$.setHeader("Content-Disposition","attachment; filename="+$rptId$$+".docx"),$res$$.write($result$$,"binary"),$res$$.end(null,"binary")):
|
|
36
|
+
$res$$.send($result$$)})}})})})},$id_rpt$$=$req$jscomp$0$$.query.id_rpt,$dir_root_templates$$=configs.paths.templates||__dirname,$templatePath$$,$rptConfig$$,$html_template$$;(new Promise(($resolve$$,$reject$$)=>{$rptConfig$$=$templatePath$$=void 0;if($id_rpt$$&&global.mongoose.Types.ObjectId.isValid($id_rpt$$))rpt.findOne({_id:$id_rpt$$}).lean().exec(async function($error$$,$r$$){if($error$$||!$r$$)return console.error("Not found excel template",$id_rpt$$,$error$$),$reject$$($error$$||"Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu");
|
|
37
|
+
if($req$jscomp$0$$.query.print)$html_template$$=$r$$.html_template;else{if(0<$r$$.file_mau_in.indexOf("/file/download")){$error$$=$r$$.file_mau_in.split("/").pop();const $file$$=global.getModel("file");try{const $_fileMauIn$$=await $file$$.findOne({_id:$error$$}).lean();if(!$_fileMauIn$$)return $reject$$("Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu");let $file_name$$=$_fileMauIn$$.file.name,$root$$=configs.paths.uploads;$root$$||($root$$=__dirname,$root$$=path.dirname($root$$),$root$$=path.join($root$$,
|
|
38
|
+
"uploads"));$templatePath$$=path.join($root$$,$file_name$$)}catch($e$$){return $reject$$($e$$.message||"Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu")}}else $templatePath$$=path.dirname($dir_root_templates$$)+$r$$.file_mau_in;fs.existsSync($templatePath$$)||(console.log("file template not found",$templatePath$$),$templatePath$$=`${path.dirname($dir_root_templates$$)}/templates/excels/reports/${$module$$}.xlsx`);fs.existsSync($templatePath$$)||($templatePath$$=`${path.dirname(__dirname)}/templates/excels/reports/${$module$$}.xlsx`);
|
|
39
|
+
if(!fs.existsSync($templatePath$$))return $reject$$("M\u1eabu kh\u00f4ng t\u1ed3n t\u1ea1i")}$rptConfig$$=$r$$;return $resolve$$($templatePath$$,$html_template$$)});else if($templatePath$$=`${path.dirname($dir_root_templates$$)}/templates/excels/reports/${$module$$}.xlsx`,fs.existsSync($templatePath$$)||($templatePath$$=`${path.dirname(__dirname)}/templates/excels/reports/${$module$$}.xlsx`),!fs.existsSync($templatePath$$))return $reject$$("M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i")})).then(()=>
|
|
40
|
+
{!1===$options$$.require_id_app?$streamData$$({}):permission.hasRight($req$jscomp$0$$.params.id_app,$req$jscomp$0$$.user.email,$module$$,"view",function($error$$,$hr$$,$app$$){$hr$$?$streamData$$({...$app$$}):$res$$.status(403).send({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xu\u1ea5t excel b\u00e1o c\u00e1o n\u00e0y"})},{notNeedRight:$options$$.notNeedRight})}).catch($e$$=>{console.error($e$$);return $e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})})}catch($e$$){return $e$$.error?
|
|
41
|
+
$res$$.status(500).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})}})}getData($req$$,$callback$$){setImmediate(()=>{try{this.fecthDataFunc($req$$,$callback$$)}catch($e$$){console.error($e$$),$callback$$($e$$.message)}})}createRoute($routeName$$,$callback$$,$_options$$={method:"GET"}){$_options$$.method=$_options$$.method?$_options$$.method.toUpperCase():"GET";const $self$$=this;let $r$$=function($req$$,$res$$){setImmediate(()=>{!1===$self$$.options.require_id_app?$callback$$($req$$,
|
|
42
|
+
function($e$$,$rs$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)},$res$$):permission.hasRight($req$$.params.id_app,$req$$.user.email,$self$$.module,"view",function($error$$,$hr$$){$hr$$?$callback$$($req$$,function($e$$,$rs$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)},$res$$):$res$$.status(403).send({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xem b\u00e1o c\u00e1o n\u00e0y"})},
|
|
43
|
+
{notNeedRight:$self$$.options.notNeedRight||$_options$$.notNeedRight})})};"DELETE"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).delete($r$$):"POST"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).post($r$$):"PUT"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).put($r$$):this.router.route(`${this.base_path+this.module}/${$routeName$$}`).get($r$$)}}module.exports=controllerRPT;
|