UNPKG

flexbiz-server

Version:

Flexible Server

90 lines (89 loc) 41.6 kB
'use strict';const EventEmitter=require("events").EventEmitter,_=require("lodash"),ckvt=require("../libs/ckvt"),OptionsModel=global.getModel("options"),Approve=global.getModel("approve"),trangthai=global.getModel("trangthai"),Participant=global.getModel("participant"),async=require("async"),crypto=require("crypto"),permission=require("../libs/permission"),utils=require("../libs/utils"),templatevoucher=global.getModel("templatevoucher"),{evalute}=require("../libs/utils"),redisCache=require("../libs/redis-cache"), dmqddvt=global.getModel("dmqddvt"),importHandler=require("./importHandler"),viewHandler=require("./viewHandler"),{bodyToJson,ERRORS,getNextSequence,postData,pushNotification,runWebhooks}=require("./controllerUtils"),handlers=require("./handlers"); class controller{constructor($router$$,$model$$,$name$$,$options$$={isVoucher:void 0,sort:void 0,check_stock:void 0,unique:void 0,require_id_app:void 0,notNeedRight:void 0}){this.name=$name$$;this.model=$model$$;this.model_name=$model$$.collection.name.substring(0,$model$$.collection.name.length-1).toLowerCase();_.has($model$$.schema.paths,"listinfo_code")||$model$$.schema.add({listinfo_code:{type:String}});this.router=$router$$;this.module=this.name;global.controllers[$name$$.trim().toUpperCase()]= this;$options$$.findExact||($options$$.findExact={});this.keyValues=$options$$.keyValues;this.keyValues||(this.keyValues={});void 0===$options$$.require_id_app||!0===$options$$.require_id_app?(this.require_id_app=!0,this.route_name=`/:id_app/${this.module}`):(this.require_id_app=!1,this.route_name=`/${this.module}`);this.collection_name=$options$$.collection_name?$options$$.collection_name:$name$$;this.sort=$options$$.sort;this.unique=$options$$.unique;this.getting=$options$$.onGetting;this.finding= $options$$.onFinding;this.found=$options$$.onFound;this.validating=$options$$.onValidating;this.saving=$options$$.onSaving;this.creating=$options$$.onCreating;this.created=$options$$.onCreated;this.updating=$options$$.onUpdating;this.updated=$options$$.onUpdated;this.deleting=$options$$.onDeleting;this.deleted=$options$$.onDeleted;this.approveData=$options$$.approveData;this.view=$options$$.onView;this.viewRequired=$options$$.onViewRequired;this.cache=$options$$.cache;this.excelParse=$options$$.onExcelParse; this.options=$options$$;this.replaceIfExists=$options$$.replaceIfExists}async asyncView($user$$,$items$$,$options$$){const $self$$=this;return new Promise($resolve$$=>{$self$$.onView($user$$,$items$$,($error$$,$rs$$)=>{if($error$$)return console.error($error$$),$resolve$$($items$$);$resolve$$($rs$$)},$options$$)})}async onView($user$$,$rows$$,$next$$,$options$$){viewHandler($user$$,this,$rows$$,$next$$,$options$$)}async notNeedRight($user$$,$_options$$={}){let $nnr$$=this.options.notNeedRight;_.isFunction($nnr$$)&& ($nnr$$=$nnr$$($user$$,$_options$$));return $nnr$$}getProperty($name$$){return this[$name$$]}getNextId(){let $ma_ct$$=this.name;this.router.route(`${this.route_name}/next/:field`).get(($field_req$$,$res$$)=>{let $id_app$$=$field_req$$.user.current_id_app;$field_req$$=$field_req$$.params.field;"so_ct"===$field_req$$?$res$$.send({[$field_req$$]:$ma_ct$$}):getNextSequence($id_app$$,$ma_ct$$,$field_req$$,($e$$,$rs$$)=>{if($e$$)return console.error("getNextId",$e$$),$e$$.error?$res$$.status(400).send($e$$): $res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)})})}async checkData($appInfo$$,$data$$,$fn$$){const $options$$=this.options;if($data$$.trang_thai&&$data$$.ma_ct){let $tt$$=await trangthai.findOne({ma_ct:$data$$.ma_ct,ma_trang_thai:$data$$.trang_thai},{check_data:1}).lean();if($tt$$&&0==$tt$$.check_data)return $fn$$()}async.series({checkTonKho:$callback$jscomp$0$$=>{$data$$.details&&$appInfo$$&&$appInfo$$.options&&$appInfo$$.options.khong_xuat_kho_am&&0!=$options$$.check_stock? (async()=>{let $details$$=$data$$.details.filter($d$$=>$d$$.ma_vt&&$d$$.sl_xuat);await $details$$.asyncJoinModel2($appInfo$$._id,"dmvt",{where:{ma_vt:"ma_vt"},fields:["tg_tk","kg_kiem_tra_ton_kho","kg_kiem_tra_ton_kho_tt",{cb:"combo"},"ten_vt"]});$details$$.forEach($d$$=>{!$d$$.combo&&$d$$.cb&&($d$$.combo=$d$$.cb)});$details$$=$details$$.filter($d$$=>$d$$.tg_tk&&!$d$$.kg_kiem_tra_ton_kho||0<($d$$.combo||[]).length);$details$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($c$$=> {$c$$=$c$$.toObject?$c$$.toObject():{...$c$$};$c$$.sl_xuat*=$detail$$.sl_xuat;$c$$.ma_kho=$detail$$.ma_kho;return $c$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);await $details$$.asyncJoinModel2($appInfo$$._id,dmqddvt,{where:{ma_vt:"ma_vt",ma_dvt:"ma_dvt"},fields:"ty_le_qd"});let $data_sokho$$=[];$data$$._id&&($data_sokho$$=await global.getModel("sokho").find({id_ct:$data$$._id.toString()}).lean());$details$$.forEach($d$$=>{$d$$.he_so_qd=$d$$.ty_le_qd||1;$d$$.sl_xuat_qd=$d$$.he_so_qd* $d$$.sl_xuat});$details$$=await $details$$.asyncGroupBy(["ma_vt","ma_kho","ten_vt"],["sl_xuat_qd"]);async.map($details$$,($d$$,$callback$$)=>{let $ma_kho$$=$d$$.ma_kho||$data$$.ma_kho||$data$$.ma_kho_x,$query$$={ma_vt:$d$$.ma_vt,ma_kho:$ma_kho$$,ngay:new Date,id_app:$appInfo$$._id};$d$$.kg_kiem_tra_ton_kho_tt||($d$$.ma_lo&&($query$$.ma_lo=$d$$.ma_lo),$d$$.han_sd&&($query$$.han_sd=$d$$.han_sd),$d$$.ma_tt1&&($query$$.ma_tt1=$d$$.ma_tt1),$d$$.ma_tt2&&($query$$.ma_tt2=$d$$.ma_tt2),$d$$.ma_tt3&&($query$$.ma_tt3= $d$$.ma_tt3));ckvt($query$$,function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$rs$$?($e$$=$rs$$.csum("ton"),$rs$$=$data_sokho$$.filter($s$$=>$s$$.ma_vt===$d$$.ma_vt&&$s$$.ma_kho===$ma_kho$$).reduce(($a$$,$b$$)=>($a$$.sl_xuat_qd||0)+($b$$.sl_xuat_qd||0),0),$d$$.sl_xuat_qd>utils.round($e$$+$rs$$,2)?$callback$$(`S\u1ea3n ph\u1ea9m ${$d$$.ma_vt} - ${$d$$.ten_vt} c\u00f3 s\u1ed1 l\u01b0\u1ee3ng xu\u1ea5t quy \u0111\u1ed5i (${$d$$.sl_xuat_qd}) l\u1edbn h\u01a1n s\u1ed1 l\u01b0\u1ee3ng t\u1ed3n quy \u0111\u1ed5i (${$e$$+ $rs$$})`):$callback$$()):$callback$$()})},$e$$=>{$callback$jscomp$0$$($e$$)})})():$callback$jscomp$0$$()}},$e$$=>{$fn$$($e$$)})}async cacheData($obj$$,$callback$$){$obj$$&&$obj$$.toObject&&($obj$$=$obj$$.toObject());await redisCache.set(this.model_name,$obj$$,$callback$$)}async deleteData($obj$$,$callback$$){$obj$$&&$obj$$.toObject&&($obj$$=$obj$$.toObject());await redisCache.remove(this.model_name,$obj$$,$callback$$)}createRoute($routeName$$,$handler_routeAction$$,$_options$$={method:"GET"}){const $self$$= this;$_options$$.method=$_options$$.method?$_options$$.method.toUpperCase():"GET";const $route_action_key$$=`route_action_${$self$$.name}_${$routeName$$}_${$_options$$.method}`;$self$$[$route_action_key$$]=$handler_routeAction$$;$handler_routeAction$$=async function($req$$,$res$$){const {query:$query$$,body:$body$$,user:$user$$,params:$params$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{const $_req$$= {handler:"createRouteHandler",routeName:$routeName$$,_options:$_options$$,route_action_key:$route_action_key$$,query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$,originalUrl:$req$$.originalUrl};global.inputMainPool?global.inputMainPool.exec({req:$_req$$,module:$self$$.name.toUpperCase(),configs:JSON.stringify(configs)},$response$$=>{if($response$$.error)return $res$$.status(400).send({error:$response$$.error,message:$response$$.message||$response$$.error}); $res$$.send($response$$.result)}):handlers.createRouteHandler($self$$,$_req$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)})}catch($e$$){$res$$.status(400).send($e$$)}};let $url$$=`${this.route_name}/${$routeName$$}`,$router$$=this.router;"DELETE"==$_options$$.method?$router$$.route($url$$).delete($handler_routeAction$$):"POST"==$_options$$.method?$router$$.route($url$$).post($handler_routeAction$$):"PUT"==$_options$$.method?$router$$.route($url$$).put($handler_routeAction$$): $router$$.route($url$$).get($handler_routeAction$$)}async requestApprove($app_info$$,$user_request$$,$obj_request$$,$next$$,$voucher_options$$,$preRequest$$){let $ctrl$$=this;if(!$app_info$$)return $next$$(null,$obj_request$$);let $obj$$;$obj$$=$obj_request$$.toObject?$obj_request$$.toObject():_.cloneDeep($obj_request$$);$obj$$.ma_ct=$obj$$.ma_ct||$ctrl$$.name;let $approveDatas$$=[];$voucher_options$$||($voucher_options$$=(await OptionsModel.findOne({id_app:$obj$$.id_app,id_func:$ctrl$$.name},{option:1}).lean()|| {}).option);$voucher_options$$&&$voucher_options$$.custom_approve_user&&$voucher_options$$.custom_approve_user.forEach($trang_thai_approve$$=>{let $update_after_approve$$,$update_after_deny$$;if($trang_thai_approve$$.update_after_approve)try{let $str_func$$=$trang_thai_approve$$.update_after_approve;0>$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);$update_after_approve$$=evalute($str_func$$)}catch($e$$){console.error("request approve",$e$$,$trang_thai_approve$$.update_after_approve), $update_after_approve$$={}}else $update_after_approve$$={};$trang_thai_approve$$.update_after_approve={module:$ctrl$$.name,data:{trang_thai:$trang_thai_approve$$.trang_thai2,...($update_after_approve$$.data||{})}};if($trang_thai_approve$$.update_after_deny)try{let $str_func$$=$trang_thai_approve$$.update_after_deny;0>$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);$update_after_deny$$=evalute($str_func$$)}catch($e$$){console.error("request approve",$e$$)}if($update_after_deny$$|| $trang_thai_approve$$.trang_thai3)$trang_thai_approve$$.update_after_deny={module:$ctrl$$.name,data:{trang_thai:$trang_thai_approve$$.trang_thai3,...(($update_after_deny$$||{}).data||{})}};$approveDatas$$.push($trang_thai_approve$$)});$approveDatas$$=$approveDatas$$.filter($approveData_condition$$=>{$approveData_condition$$=$approveData_condition$$.condition;if(!$approveData_condition$$)return!0;0>$approveData_condition$$.indexOf("return ")&&($approveData_condition$$=`return ${$approveData_condition$$}`); try{return evalute($approveData_condition$$,{master:$obj$$,data:$obj$$})}catch($e$$){return console.error("check condition approve",$e$$,$approveData_condition$$),!1}});$approveDatas$$.filter($a$$=>$a$$.approve_users).forEach($approveData$$=>{setImmediate(()=>{let $title$$=$approveData$$.title||"Y\u00eau c\u1ea7u duy\u1ec7t";if(0<=$title$$.indexOf("return ")){var $ds_nguoi_duyet_str_func$$=$title$$;try{$title$$=evalute($ds_nguoi_duyet_str_func$$,{master:$obj$$,data:$obj$$})}catch($e$$){console.error("request approve", $e$$,$ds_nguoi_duyet_str_func$$)}}$ds_nguoi_duyet_str_func$$=$approveData$$.approve_users;let $update_after_approve$$=$approveData$$.update_after_approve,$update_after_deny$$=$approveData$$.update_after_deny;if(_.isString($ds_nguoi_duyet_str_func$$))try{let $str_func$$=$ds_nguoi_duyet_str_func$$;0>$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);$ds_nguoi_duyet_str_func$$=evalute($str_func$$,{master:$obj$$,data:$obj$$,preRequest:$preRequest$$});if(!_.isArray($ds_nguoi_duyet_str_func$$)){console.error("danh s\u00e1ch ng\u01b0\u1eddi duy\u1ec7t ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng, hi\u1ec7n t\u1ea1i \u0111ang l\u00e0", $ds_nguoi_duyet_str_func$$);return}}catch($e$$){console.error("request approve",$e$$,$ds_nguoi_duyet_str_func$$);return}if($approveData$$.approve_users_custom)try{let $str_func$$=$approveData$$.approve_users_custom;0>$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);let $ds_nguoi_duyet_custom$$=evalute($str_func$$,{master:$obj$$,data:$obj$$,preRequest:$preRequest$$});$ds_nguoi_duyet_custom$$&&(_.isArray($ds_nguoi_duyet_custom$$)?$ds_nguoi_duyet_str_func$$=[...$ds_nguoi_duyet_str_func$$, ...$ds_nguoi_duyet_custom$$]:console.error("danh s\u00e1ch ng\u01b0\u1eddi duy\u1ec7t ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng, hi\u1ec7n t\u1ea1i \u0111ang l\u00e0",$ds_nguoi_duyet_custom$$))}catch($e$$){console.error("request approve",$e$$,$approveData$$.approve_users_custom)}if($ds_nguoi_duyet_str_func$$&&0!==$ds_nguoi_duyet_str_func$$.length&&($ds_nguoi_duyet_str_func$$=[...(new Set($ds_nguoi_duyet_str_func$$))],$obj$$.trang_thai==$approveData$$.trang_thai)){let $user_approves$$=$ds_nguoi_duyet_str_func$$.map($nguoi_duyet$$=> ({email:$nguoi_duyet$$,name:$nguoi_duyet$$}));$user_approves$$.joinModel2($obj$$.id_app,Participant,{where:"email",fields:"name"},()=>{[$user_request$$].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||$e$$)},$update_after_approve$$,$approveData$$.template_content,$update_after_deny$$)})})}})});$next$$(null,$obj$$)}async import($user$$,$id_app$$, $data$$,$callback_main$$,$options$$={replace:!0,req:null}){importHandler($user$$,this,$id_app$$,$data$$,$callback_main$$,$options$$)}postData($obj$$,$callback$$,$options$$={}){return controller.postData($obj$$,this,$callback$$,$options$$)}pushNotification($_obj$$,$eventName$$="new",$old_obj$$=null,$justFireEvents$$=!1,$options$$={title:"",data:{}}){return pushNotification(this,$_obj$$,$eventName$$,$old_obj$$,$justFireEvents$$,$options$$)}}controller.prototype.__proto__=EventEmitter.prototype; controller.prototype.asyncGetNextSequence=async($id_app$$,$ma_ct$$,$field$$="so_ct",$options$$)=>new Promise($resolve$$=>{getNextSequence($id_app$$,$ma_ct$$,$field$$,($error$$,$rs$$)=>{if($error$$)return Error($error$$);$resolve$$($rs$$)},$options$$)}); controller.prototype.getFieldNoRight=function(){let $ctrl$$=this;this.router.route(`${this.route_name}/field-not-right/:fieldName`).get(async($req$$,$res$$)=>{let $fieldName$$=$req$$.params.fieldName;try{0<=(await permission.getFieldNotRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.name)).indexOf($fieldName$$)?$res$$.send({allow:!1}):$res$$.send({allow:!0})}catch($e$$){$res$$.state(400).send($e$$.message)}})}; controller.prototype.find=function($_route_name_route_name$$,$shareRoute$$=!1,$method$$="GET"){let $ctrl$$=this;const $handlerResult$$=($res$$,$data$$)=>{const {result:$result$$,dataType:$dataType$$}=$data$$;"xlsx"==$dataType$$?($res$$.setHeader("Content-Type","application/vnd.openxmlformats"),$res$$.setHeader("Content-Disposition","attachment; filename="+$ctrl$$.name+".xlsx"),$res$$.end($result$$,"binary")):$res$$.send($result$$)},$findRoute$$=async($ip$jscomp$1_req$$,$res$$)=>{const {query:$query$$, body:$body$$,user:$user$$,params:$params$$}=$ip$jscomp$1_req$$;var $_req$jscomp$1_user_agent$$=$ip$jscomp$1_req$$.header("user-agent");$ip$jscomp$1_req$$=$ip$jscomp$1_req$$.headers["x-forwarded-for"]||$ip$jscomp$1_req$$.connection.remoteAddress;try{if($_req$jscomp$1_user_agent$$={handler:"findHandler",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$_req$jscomp$1_user_agent$$,ip:$ip$jscomp$1_req$$,shareRoute:$shareRoute$$},global.inputMainPool){const $id_task$$=`task-find-${crypto.randomBytes(20).toString("hex")}`; global.inputMainPool.exec({id_task:$id_task$$,req:$_req$jscomp$1_user_agent$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$response$$=>{if($response$$.error)return $res$$.status(400).send({error:$response$$.error,message:$response$$.message||$response$$.error});$handlerResult$$($res$$,$response$$.result)})}else handlers.findHandler($ctrl$$,$_req$jscomp$1_user_agent$$,($e$$,$returnvalue$$)=>{if($e$$)return $res$$.status(400).send($e$$);$handlerResult$$($res$$,$returnvalue$$)})}catch($e$$){$res$$.status(400).send($e$$)}}; $_route_name_route_name$$=$_route_name_route_name$$||this.route_name;"GET"===$method$$?(this.router.route($_route_name_route_name$$).get($findRoute$$),this.router.route($_route_name_route_name$$+"/excel").get($findRoute$$)):(this.router.route($_route_name_route_name$$).post($findRoute$$),this.router.route($_route_name_route_name$$+"/excel").post($findRoute$$))}; controller.prototype.get=function($route_name$$,$shareRoute$$=!1){const $ctrl$$=this;this.router.route(`${$route_name$$||this.route_name}/:id`).get(async function($req$$,$res$$){var $body$$=$req$$.params.id;if(!global.mongoose.Types.ObjectId.isValid($body$$))return $res$$.status(404).send({error:ERRORS.ERR_ID_INVALID,code:ERRORS.ERR_ID_INVALID_CODE});$body$$={_id:$body$$};const $user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress,{query:$query$$, user:$user$$,params:$params$$}=$req$$;try{handlers.findHandler($ctrl$$,{query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,shareRoute:$shareRoute$$,originalUrl:$req$$.originalUrl},($e$jscomp$16_result$$,$returnvalue$$)=>{if($e$jscomp$16_result$$)return $res$$.status(400).send($e$jscomp$16_result$$);({result:$e$jscomp$16_result$$}=$returnvalue$$);if(0==$e$jscomp$16_result$$.length)return $res$$.status(404).send({error:ERRORS.ERR_NOT_FOUND,code:ERRORS.ERR_NOT_FOUND_CODE}); $res$$.send($e$jscomp$16_result$$[0])})}catch($e$$){console.error($e$$),$res$$.status(400).send($e$$)}})}; controller.prototype.postAgainHandler=function($user$$,$condition$$,$callback$jscomp$0$$,$options$$={req:null}){let $model$$=this.model,$ctrl$$=this;if(!$ctrl$$.post)return $callback$jscomp$0$$(null,{message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n xong"});const $update_tk_vt$$=$condition$$.update_tk_vt;delete $condition$$.update_tk_vt;const $user_update$$={date_updated:new Date,user_updated:$user$$.email};$model$$.find($condition$$).sort({ngay_ct:1}).lean().exec(function($e$jscomp$0$$, $objsrepost$$){console.log("start repost",$condition$$,$objsrepost$$.length," vouchers","by",$user$$.email);setImmediate(()=>{if($e$jscomp$0$$)return console.error("postAgain: find",$e$jscomp$0$$),$callback$jscomp$0$$({error:$e$jscomp$0$$.message||$e$jscomp$0$$.error||$e$jscomp$0$$});async.map($objsrepost$$,function($obj$$,$callback$$){setImmediate(async()=>{console.log("postAgain: handle data before post",$obj$$.ma_ct,$obj$$.so_ct,$obj$$.ngay_ct,"by",$user$$.email);if($ctrl$$.reposting)try{await $ctrl$$.reposting($user$$, $obj$$)}catch($e$$){return $callback$$({error:"Kh\u00f4ng th\u1ec3 x\u1eed l\u00fd \u0111\u01b0\u1ee3c d\u1eef li\u1ec7u tr\u01b0\u1edbc khi repost ch\u1ee9ng t\u1eeb:"+$obj$$.so_ct+", L\u1ed7i: "+($e$$.message||$e$$.error||"")})}$update_tk_vt$$&&$obj$$.details&&(console.log("postAgain: update tk_vt..."),await $obj$$.details.filter($d$$=>$d$$.ma_vt).asyncJoinModel2($obj$$.id_app,global.getModel("dmvt"),{where:"ma_vt",fields:"tk_vt"}),$user_update$$.details=$obj$$.details);try{console.log("postAgain: update voucher..."), await $model$$.updateOne({_id:$obj$$._id},{...$user_update$$})}catch($e$$){return console.error("postAgain: error update data before repost",$e$$),$callback$$({error:"Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u01b0\u1ee3c d\u1eef li\u1ec7u ch\u1ee9ng t\u1eeb "+$obj$$.so_ct+",Error:"+$e$$.message||$e$$.error||""})}console.log("postAgain: posting...");postData($obj$$,$ctrl$$,function($e$$,$rs$$){console.log("postAgain: reported",$obj$$.ma_ct,$obj$$.so_ct,$obj$$.ngay_ct,"by",$user$$.email);if($e$$)return $callback$$({error:$e$$.message|| $e$$.error||"Kh\u00f4ng th\u1ec3 post s\u1ed5 s\u00e1ch ch\u1ee9ng t\u1eeb:"+$obj$$.so_ct});$callback$$(null,$rs$$)},{req:$options$$.req})})},function($e$$){if($e$$)return console.error("postAgain: Error",$e$$),$callback$jscomp$0$$({error:$e$$.message||$e$$.error||$e$$});console.log("postAgain: finished",$condition$$,$objsrepost$$.length," vouchers","by",$user$$.email);$callback$jscomp$0$$(null,{message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n xong"})})})})}; controller.prototype.updateBook=function(){let $ctrl$$=this;this.router.route(`${this.route_name}/action/postagain`).get(async($req$$,$res$$)=>{const {query:$query$$,body:$body$$,user:$user$$,params:$params$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{const $_req$$={handler:"updateBookHandler",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$, originalUrl:$req$$.originalUrl};if(global.importDataMainPool){const $id_task$$=`task-update-book-${crypto.randomBytes(20).toString("hex")}`;$res$$.send({message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. Khi ho\u00e0n th\u00e0nh, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd g\u1eedi cho b\u1ea1n m\u1ed9t th\u00f4ng b\u00e1o",status_task:`${configs.api_url||configs.domain}/task-status/${$id_task$$}`});global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(), configs:JSON.stringify(configs)},$e$jscomp$23_response$$=>{if($e$jscomp$23_response$$=$e$jscomp$23_response$$.error)return global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt l\u1ea1i s\u1ed5 s\u00e1ch",$e$jscomp$23_response$$.message||$e$jscomp$23_response$$.error||$e$jscomp$23_response$$,null,{id_app:$req$$.user.current_id_app},!0,$req$$.access_token,!0);global.getModel("notification").createNotification($req$$.user.email, $req$$.user.email,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 c\u1eadp nh\u1eadt l\u1ea1i s\u1ed5 s\u00e1ch xong","Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 c\u1eadp nh\u1eadt l\u1ea1i s\u1ed5 s\u00e1ch xong",null,{id_app:$req$$.user.current_id_app},!0,$req$$.access_token,!0)})}else $res$$.send({message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. Khi ho\u00e0n th\u00e0nh, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd g\u1eedi cho b\u1ea1n m\u1ed9t th\u00f4ng b\u00e1o"}),handlers.updateBookHandler($ctrl$$, $_req$$,$e$$=>{if($e$$)return global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt l\u1ea1i s\u1ed5 s\u00e1ch",$e$$.message||$e$$.error||$e$$,null,{id_app:$req$$.user.current_id_app},!0,$req$$.access_token,!0);global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 c\u1eadp nh\u1eadt l\u1ea1i s\u1ed5 s\u00e1ch xong","Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 c\u1eadp nh\u1eadt l\u1ea1i s\u1ed5 s\u00e1ch xong", null,{id_app:$req$$.user.current_id_app},!0,$req$$.access_token,!0)})}catch($e$$){$res$$.status(400).send($e$$)}})}; controller.prototype.updateKey=function(){let $ctrl$$=this;this.router.route(`${this.route_name}/updatekey/:_id/:field/:new_value`).get(async function($req$$,$res$$){const {query:$query$$,body:$body$$,user:$user$$,params:$params$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{handlers.updateKeyHandler($ctrl$$,{type_job:"updateKey",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$, ip:$ip$$,files:$files$$,originalUrl:$req$$.originalUrl},($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)})}catch($e$$){$res$$.status(400).send($e$$)}})}; controller.prototype.updateField=function(){let $ctrl$$=this;this.router.route(`${this.route_name}/update/:field`).get(async function($req$$,$res$$){const {query:$query$$,body:$body$$,user:$user$$,params:$params$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{handlers.updateFieldHandler($ctrl$$,{type_job:"updateField",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$, files:$files$$,originalUrl:$req$$.originalUrl},($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)})}catch($e$$){$res$$.status(400).send($e$$)}})}; controller.prototype.exportToExcel=function(){let $ctrl$$=this;const $handlerResult$$=($res$$,$returnvalue$$)=>{switch($returnvalue$$.ext){case "xlsx":$res$$.setHeader("Content-Type","application/vnd.openxmlformats");$res$$.setHeader("Content-Disposition","attachment; filename="+$ctrl$$.name+".xlsx");$res$$.end($returnvalue$$.data,"binary");break;case "docx":$res$$.setHeader("Content-Type","application/vnd.openxmlformats-officedocument.wordprocessingml.document");$res$$.setHeader("Content-Disposition", "attachment; filename="+$ctrl$$.name+".docx");$res$$.write($returnvalue$$.data,"binary");$res$$.end(null,"binary");break;case "print":$res$$.send($returnvalue$$.data.join('<p style="page-break-before: always"></p>'));break;case "json":$res$$.json($returnvalue$$.data);break;default:$res$$.send($returnvalue$$.data)}};this.router.route(`${this.route_name}/excel/:rpt_id`).get(async function($req$$,$res$$){const {query:$query$$,body:$body$$,user:$user$$,params:$params$$}=$req$$,$user_agent$$=$req$$.header("user-agent"), $ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{const $_req$$={handler:"exportHandler",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,originalUrl:$req$$.originalUrl};global.inputMainPool?global.inputMainPool.exec({req:$_req$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$response$$=>{if($response$$.error)return $res$$.status(400).send({error:$response$$.error,message:$response$$.message||$response$$.error}); $handlerResult$$($res$$,$response$$.result)}):handlers.exportHandler($ctrl$$,$_req$$,($e$$,$returnvalue$$)=>{if($e$$)return $res$$.status(400).send($e$$);$handlerResult$$($res$$,$returnvalue$$)})}catch($e$$){$res$$.status(400).send($e$$)}})}; controller.prototype.importFromGoogleSheet=function(){let $ctrl$$=this;this.router.route(`${this.route_name}/import/googlesheet`).get(async function($req$$,$res$$){const {query:$query$$,body:$body$$,user:$user$$,params:$params$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{const $_req$$={handler:"importFromGsHandler",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,originalUrl:$req$$.originalUrl}; if(global.importDataMainPool){const $id_task$$=`task-import-google-sheet-${crypto.randomBytes(20).toString("hex")}`;$res$$.send({message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. Khi ho\u00e0n th\u00e0nh, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd g\u1eedi cho b\u1ea1n m\u1ed9t th\u00f4ng b\u00e1o",status_task:`${configs.api_url||configs.domain}/task-status/${$id_task$$}`});global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)}, $e$jscomp$32_response$$=>{if($e$jscomp$32_response$$=$e$jscomp$32_response$$.error)return global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$jscomp$32_response$$.message||$e$jscomp$32_response$$.error||$e$jscomp$32_response$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong", "Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong",null,{id_app:$req$$.user.current_id_app},!0,null,!0)})}else $res$$.send({message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. Khi ho\u00e0n th\u00e0nh, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd g\u1eedi cho b\u1ea1n m\u1ed9t th\u00f4ng b\u00e1o"}),handlers.importFromGsHandler($ctrl$$,$_req$$,$e$$=>{if($e$$)return global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u", $e$$.message||$e$$.error||$e$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong","Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong",null,{id_app:$req$$.user.current_id_app},!0,null,!0)})}catch($e$$){$res$$.status(400).send($e$$)}})}; controller.prototype.importFromJson=function(){let $ctrl$$=this;this.router.route(`${this.route_name}/import/json`).post(async function($req$$,$res$$){const {query:$query$$,body:$body$$,user:$user$$,params:$params$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{const $_req$$={handler:"importFromJsonHandler",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$, originalUrl:$req$$.originalUrl};if(global.importDataMainPool){const $id_task$$=`task-import-json-${crypto.randomBytes(20).toString("hex")}`;$res$$.send({message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. Khi ho\u00e0n th\u00e0nh, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd g\u1eedi cho b\u1ea1n m\u1ed9t th\u00f4ng b\u00e1o",status_task:`${configs.api_url||configs.domain}/task-status/${$id_task$$}`});global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(), configs:JSON.stringify(configs)},$e$jscomp$35_response$$=>{if($e$jscomp$35_response$$=$e$jscomp$35_response$$.error)return global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$jscomp$35_response$$.message||$e$jscomp$35_response$$.error||$e$jscomp$35_response$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong", "Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong",null,{id_app:$req$$.user.current_id_app},!0,null,!0)})}else $res$$.send({message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. Khi ho\u00e0n th\u00e0nh, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd g\u1eedi cho b\u1ea1n m\u1ed9t th\u00f4ng b\u00e1o"}),handlers.importFromJsonHandler($ctrl$$,$_req$$,$e$$=>{if($e$$)return global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u", $e$$.message||$e$$.error||$e$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong","Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong",null,{id_app:$req$$.user.current_id_app},!0,null,!0)})}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$$),$res$$.status(400).send($e$$)}})}; controller.prototype.importFromExcel=function(){let $ctrl$$=this;this.router.route(`${this.route_name}/import/excel`).post(async function($req$$,$res$$){const {query:$query$$,body:$body$$,user:$user$$,params:$params$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{const $_req$$={handler:"importFromExcelHandler",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$, originalUrl:$req$$.originalUrl};if(global.importDataMainPool){const $id_task$$=`task-import-excel-${crypto.randomBytes(20).toString("hex")}`;$res$$.send({message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. Khi ho\u00e0n th\u00e0nh, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd g\u1eedi cho b\u1ea1n m\u1ed9t th\u00f4ng b\u00e1o",status_task:`${configs.api_url||configs.domain}/task-status/${$id_task$$}`});global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(), configs:JSON.stringify(configs)},$e$jscomp$38_response$$=>{if($e$jscomp$38_response$$=$e$jscomp$38_response$$.error)return global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$jscomp$38_response$$.message||$e$jscomp$38_response$$.error||$e$jscomp$38_response$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong", "Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong",null,{id_app:$req$$.user.current_id_app},!0,null,!0)})}else $res$$.send({message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. Khi ho\u00e0n th\u00e0nh, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd g\u1eedi cho b\u1ea1n m\u1ed9t th\u00f4ng b\u00e1o"}),handlers.importFromExcelHandler($ctrl$$,$_req$$,$e$$=>{if($e$$)return global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u", $e$$.message||$e$$.error||$e$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong","Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 import d\u1eef li\u1ec7u xong",null,{id_app:$req$$.user.current_id_app},!0,null,!0)})}catch($e$$){$res$$.status(400).send($e$$)}})}; controller.prototype.create=function(){let $ctrl$$=this;this.router.route(this.route_name).post(async function($req$$,$res$$){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<_.keys($req$$.files).length&&("JSON"!=$body$$.return&&($req$$.uploadFile=!0),_.extend($body$$,$req$$.files));const {query:$query$$,user:$user$$,params:$params$$,files:$files$$,uploadFile:$uploadFile$$}=$req$$,$user_agent$$=$req$$.header("user-agent"), $ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{handlers.createHandler($ctrl$$,{query:$query$$,data:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$,uploadFile:$uploadFile$$,originalUrl:$req$$.originalUrl},($e$$,$returnvalue$$)=>{if($e$$)return $res$$.status(400).send($e$$);!1===$req$$.query.return_data?$res$$.send({_id:$returnvalue$$._id.toString()}):$res$$.send($returnvalue$$)})}catch($e$$){$res$$.status(400).send($e$$)}})}; controller.prototype.quickCreate=function(){let $model$$=this.model,$name$$=this.name,$ctrl$$=this,$createFromTemplate$$=async($req$$,$res$$,$body$jscomp$11_query$$)=>{if(!$body$jscomp$11_query$$){$body$jscomp$11_query$$=$req$$.params.template_code;if(!$body$jscomp$11_query$$)return $res$$.status(400).send({error:"M\u1eabu d\u1eef li\u1ec7u kh\u00f4ng t\u1ed3n t\u1ea1i"});$body$jscomp$11_query$$={id_app:$req$$.user.current_id_app,voucher_code:$name$$.toUpperCase(),code:$body$jscomp$11_query$$};$body$jscomp$11_query$$= await templatevoucher.findOne($body$jscomp$11_query$$).lean();if(!$body$jscomp$11_query$$)return $res$$.status(400).send({error:"M\u1eabu d\u1eef li\u1ec7u kh\u00f4ng t\u1ed3n t\u1ea1i"})}$body$jscomp$11_query$$=$body$jscomp$11_query$$.data||{};delete $body$jscomp$11_query$$.so_ct;delete $body$jscomp$11_query$$.ngay_ct;delete $body$jscomp$11_query$$.user_created;delete $body$jscomp$11_query$$.date_created;delete $body$jscomp$11_query$$.user_updated;delete $body$jscomp$11_query$$.date_updated;delete $body$jscomp$11_query$$._id; delete $body$jscomp$11_query$$.pkey;delete $body$jscomp$11_query$$.__v;let $_data$$=$req$$.query;$req$$.body&&($_data$$=Object.assign($_data$$,$req$$.body));for(let $key$$ in $_data$$)$_data$$[$key$$]&&"access_token"!==$key$$&&"token"!==$key$$&&"_id"!==$key$$&&(_.has($model$$.schema.paths,$key$$)&&($body$jscomp$11_query$$[$key$$]=$_data$$[$key$$]),$body$jscomp$11_query$$.details&&$body$jscomp$11_query$$.details.forEach($d$$=>{$d$$[$key$$]=$_data$$[$key$$]}));const {query:$query$$,user:$user$$,params:$params$$, files:$files$$,uploadFile:$uploadFile$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{handlers.createHandler($ctrl$$,{query:$query$$,body:$body$jscomp$11_query$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$,uploadFile:$uploadFile$$,originalUrl:$req$$.originalUrl},($e$$,$returnvalue$$)=>{if($e$$)return $res$$.status(400).send($e$$);!1===$req$$.query.return_data?$res$$.send({_id:$returnvalue$$._id.toString()}): $res$$.send($returnvalue$$)})}catch($e$$){$res$$.status(400).send($e$$)}};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$$)})}; controller.prototype.update=function(){let $ctrl$$=this;this.router.route(this.route_name+"/:id").put(async function($req$$,$res$$){let $body$$=$req$$.body;$req$$.files&&_.extend($body$$,$req$$.files);let $data$$;try{$data$$=bodyToJson($body$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$})}const {query:$query$$,user:$user$$,params:$params$$,files:$files$$,uploadFile:$uploadFile$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]|| $req$$.connection.remoteAddress,$id$$=$req$$.params.id;try{handlers.updateHandler($ctrl$$,{query:$query$$,id:$id$$,data:$data$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$,uploadFile:$uploadFile$$,originalUrl:$req$$.originalUrl},($e$$,$returnvalue$$)=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});!1===$req$$.query.return_data?$res$$.send({_id:$returnvalue$$._id.toString()}):$res$$.send($returnvalue$$)})}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt d\u1eef li\u1ec7u", $e$$),$res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$})}})}; controller.prototype.delete=function(){let $ctrl$$=this;this.router.route(this.route_name+"/:id").delete(async($req$$,$res$$)=>{const {query:$query$$,body:$body$$,user:$user$$,params:$params$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{handlers.deleteHandler($ctrl$$,{query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$,originalUrl:$req$$.originalUrl}, ($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});$res$$.send($rs$$)})}catch($e$$){$res$$.status(400).send($e$$)}})}; controller.prototype.deleteMany=function($route_name$$){let $ctrl$$=this;this.router.route(`${$route_name$$||this.route_name}/action/delete`).delete(async($req$$,$res$$)=>{const {query:$query$$,body:$body$$,user:$user$$,params:$params$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{handlers.deleteManyHandler($ctrl$$,{type_job:"deleteMany",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$, ip:$ip$$,originalUrl:$req$$.originalUrl},($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});$res$$.send($rs$$)})}catch($e$$){$res$$.status(400).send($e$$)}})}; controller.prototype.history=function(){let $ctrl$$=this;this.router.route(this.route_name+"/g/history/:id").get(async function($req$$,$res$$){const {query:$query$$,body:$body$$,user:$user$$,params:$params$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{handlers.historyHandler($ctrl$$,{type_job:"history",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$, originalUrl:$req$$.originalUrl},($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});$res$$.send($rs$$)})}catch($e$$){$res$$.status(400).send($e$$)}})}; controller.prototype.logs=function(){let $ctrl$$=this;this.router.route(this.route_name+"/g/log/:action").get(async function($req$$,$res$$){const {query:$query$$,body:$body$$,user:$user$$,params:$params$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{handlers.logHandler($ctrl$$,{type_job:"log",query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$,originalUrl:$req$$.originalUrl}, ($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});$res$$.send($rs$$)})}catch($e$$){$res$$.status(400).send($e$$)}})};controller.prototype.postData=($obj$$,$cb$$,$options$$={})=>postData($obj$$,this,$cb$$,$options$$); controller.prototype.route=function($setRoute$$){this.history();this.logs();this.find("/search"+this.route_name,!1,"POST");this.find();this.get();this.find(`/${this.module}/shared`,!0);this.get(`/${this.module}/shared`,!0);this.getFieldNoRight();this.create();this.quickCreate();this.update();this.delete();this.deleteMany();this.getNextId();this.exportToExcel();this.importFromExcel();this.importFromJson();this.importFromGoogleSheet();this.updateField();this.updateKey();this.updateBook();$setRoute$$&& $setRoute$$(this.router)};controller.runWebhooks=runWebhooks;controller.postData=postData;controller.pushNotification=pushNotification;controller.create=async($user$$,$ctrl$$,$data$$,$callback$$,$id_be_supply_by_user$$,$req$$,$action$$="add")=>{$req$$=$req$$||{};$req$$.user=$user$$;$req$$.data=$data$$;$req$$.id_be_supply_by_user=$id_be_supply_by_user$$;$req$$.action=$action$$;return handlers.createHandler($ctrl$$,$req$$,$callback$$)};module.exports=controller;