flexbiz-server 12.7.6 → 12.7.8
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 +3 -3
- package/server/auths/rateLimiterMiddleware.js +3 -3
- package/server/controllers/controller.js +41 -41
- package/server/controllers/controllerUtils.js +61 -61
- package/server/controllers/controllerUtils_v1.js +72 -0
- package/server/controllers/controller_old.js +129 -0
- package/server/controllers/createHandler.js +34 -34
- package/server/controllers/createHandler_old.js +35 -0
- package/server/controllers/deleteHandler.js +11 -12
- package/server/controllers/deleteHandler_old.js +12 -0
- package/server/controllers/exportHandler.js +19 -17
- package/server/controllers/exportHandler_old.js +17 -0
- package/server/controllers/findHandler.js +61 -55
- package/server/controllers/findHandler_old.js +74 -0
- package/server/controllers/importFromGsHandler.js +10 -10
- package/server/controllers/importFromJsonHandler.js +6 -6
- package/server/controllers/importFromJsonHandler_old.js +6 -0
- package/server/controllers/updateBookHandler.js +1 -1
- package/server/controllers/updateFieldHandler.js +12 -13
- package/server/controllers/updateFieldHandler_old.js +13 -0
- package/server/controllers/updateHandler.js +38 -40
- package/server/controllers/updateHandler_old.js +40 -0
- package/server/controllers/viewHandler.js +13 -14
- package/server/controllers/viewHandler_old.js +14 -0
- package/server/flow/nodes/aiAnalysis.js +1 -1
- package/server/global.js +3 -5
- package/server/libs/WorkerStaticPool.js +14 -14
- package/server/libs/asyncCompat.js +10 -0
- package/server/libs/createSocaitheongay.js +1 -1
- package/server/libs/invoiceVnpt.js +1 -1
- package/server/libs/post-book.js +2 -2
- package/server/libs/post-sokho.js +5 -5
- package/server/libs/redis-cache.js +2 -2
- package/server/models/assabcihandler.js +1 -1
- package/server/models/counter.js +2 -2
- package/server/models/listinfo.js +200 -225
- package/server/models/listinfo_old.js +124 -0
- package/server/models/po1.js +4 -4
- package/server/models/purchase_contract.js +3 -3
- package/server/models/smsaccount.js +2 -2
- package/server/models/tdttco.js +3 -3
- package/server/models/tdttno.js +3 -3
- package/server/modules/lists/ls-afflink.js +1 -1
- package/server/modules/lists/ls-assbooking.js +1 -1
- package/server/modules/lists/ls-assinvestment.js +11 -11
- package/server/modules/lists/ls-asskey.js +2 -2
- package/server/modules/lists/ls-assneedtobuy.js +1 -1
- package/server/modules/lists/ls-assperiod.js +1 -1
- package/server/modules/lists/ls-asssell.js +1 -1
- package/server/modules/lists/ls-cart.js +14 -14
- package/server/modules/lists/ls-congdoansx.js +1 -1
- package/server/modules/lists/ls-consultant.js +2 -2
- package/server/modules/lists/ls-dkhoc.js +2 -2
- package/server/modules/lists/ls-dmban.js +1 -1
- package/server/modules/lists/ls-dmbp.js +2 -2
- package/server/modules/lists/ls-dmdoi.js +1 -1
- package/server/modules/lists/ls-dmnhtask.js +2 -2
- package/server/modules/lists/ls-dmvt.js +3 -3
- package/server/modules/lists/ls-file.js +1 -1
- package/server/modules/lists/ls-giaoca.js +1 -1
- package/server/modules/lists/ls-introducer.js +2 -2
- package/server/modules/lists/ls-kbm-bcqt.js +1 -1
- package/server/modules/lists/ls-news.js +1 -1
- package/server/modules/lists/ls-participant.js +1 -1
- package/server/modules/lists/ls-rpt.js +1 -1
- package/server/modules/lists/ls-smsaccount.js +1 -1
- package/server/modules/lists/ls-sosanxuat.js +1 -1
- package/server/modules/lists/ls-support.js +1 -1
- package/server/modules/public/callin.js +1 -1
- package/server/modules/reports/calc-tinhgiafifo.js +1 -1
- package/server/modules/reports/calc-tinhgiatb.js +1 -1
- package/server/modules/reports/calc-tinhgiathanh.js +1 -1
- package/server/modules/reports/calc-tinhluong.js +1 -1
- package/server/modules/reports/rp-assbonus.js +1 -1
- package/server/modules/reports/rp-bkchamcong.js +1 -1
- package/server/modules/reports/rp-cdpsdiem.js +1 -1
- package/server/modules/reports/rp-cdpskh.js +1 -1
- package/server/modules/reports/rp-cdpsnphep.js +1 -1
- package/server/modules/reports/rp-kcsns.js +1 -1
- package/server/modules/reports/rp-sctbhxh.js +1 -1
- package/server/modules/reports/rp-sctluong.js +1 -1
- package/server/modules/reports/rp-sctthuetncn.js +1 -1
- package/server/modules/reports/rp-sctvt.js +1 -1
- package/server/modules/reports/rp-sctvtnpp.js +1 -1
- package/server/modules/reports/rp-sctvttt.js +1 -1
- package/server/modules/reports/rp-thgt.js +1 -1
- package/server/modules/systems/sys-labelinfo.js +2 -3
- package/server/modules/systems/sys-listinfo.js +1 -1
- package/server/modules/systems/sys-menuinfo.js +1 -4
- package/server/modules/systems/sys-moduleinfo.js +2 -4
- package/server/modules/systems/sys-notification.js +1 -1
- package/server/route.js +1 -1
- package/server/workers/backupApp.js +1 -1
- package/server/workers/calcGrid.js +1 -1
- package/server/workers/runScript.js +1 -1
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "flexbiz-server",
|
|
3
3
|
"main": "./server/app.js",
|
|
4
4
|
"description": "Flexible Server",
|
|
5
|
-
"version": "12.7.
|
|
5
|
+
"version": "12.7.8",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Van Truong Pham",
|
|
8
8
|
"email": "invncur@gmail.com"
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"moment-timezone": "^0.5.33",
|
|
62
62
|
"mongodb-backup": "^1.6.9",
|
|
63
63
|
"mongodb-restore": "^1.6.2",
|
|
64
|
-
"mongoose": "^
|
|
65
|
-
"mongoose-storage-usage": "^1.
|
|
64
|
+
"mongoose": "^6.13.10",
|
|
65
|
+
"mongoose-storage-usage": "^1.7.0",
|
|
66
66
|
"morgan": "^1.10.0",
|
|
67
67
|
"multer": "^0.1.8",
|
|
68
68
|
"natives": "^1.1.6",
|
|
@@ -3,9 +3,9 @@ async function getDomainConfig($origin$$){var $cached_data$$=domainCache.get($or
|
|
|
3
3
|
{data:$cached_data$$,expiresAt:Date.now()+DOMAIN_CACHE_TTL_MS});return $cached_data$$}function getClientIp($raw_req$$){const $xff$$=$raw_req$$.headers["x-forwarded-for"];$raw_req$$=$raw_req$$.ip||($xff$$?$xff$$.split(",")[0].trim():void 0)||$raw_req$$.socket&&$raw_req$$.socket.remoteAddress||"unknown";return $raw_req$$.startsWith("::ffff:")?$raw_req$$.slice(7):$raw_req$$}
|
|
4
4
|
function getOrigin($raw$jscomp$1_req$$){$raw$jscomp$1_req$$=($raw$jscomp$1_req$$.headers.origin||$raw$jscomp$1_req$$.headers.referer||"").toString().trim();if(!$raw$jscomp$1_req$$)return"";try{return(new URL(/^https?:\/\//i.test($raw$jscomp$1_req$$)?$raw$jscomp$1_req$$:`https://${$raw$jscomp$1_req$$}`)).hostname.toLowerCase().replace(/^www\./,"")}catch($e$$){return""}}
|
|
5
5
|
function parseTrustDomains(){return((global.configs||{}).trust_domains||"").toString().toLowerCase().split(",").map($d$$=>$d$$.trim()).filter(Boolean)}
|
|
6
|
-
async function resolvePoints($req$$,$origin$$,$
|
|
7
|
-
|
|
6
|
+
async function resolvePoints($req$$,$origin$$,$trustKey$$,$totalPoints$$,$keyPrefix$$){var $penaltyPoints_trustDomains$$=parseTrustDomains();if($penaltyPoints_trustDomains$$.includes($origin$$))return{points:1};const $trustKeys$$=(global.configs||{}).trust_keys||[];if($trustKeys$$.length>0&&$trustKeys$$.includes($trustKey$$))return{points:1};const $domainConfig$$=await getDomainConfig($origin$$);if($domainConfig$$)return $domainConfig$$.not_allow?{blocked:!0}:{points:$domainConfig$$.points||1};if($penaltyPoints_trustDomains$$.length===
|
|
7
|
+
0&&$trustKeys$$.length===0)return{points:1};$penaltyPoints_trustDomains$$=Math.max(1,Math.round($totalPoints$$/2));Logger.warn("[rateLimiter] untrusted origin, higher point cost",{keyPrefix:$keyPrefix$$,origin:$origin$$,trustKeys:$trustKeys$$,trustKey:$trustKey$$,points:$penaltyPoints_trustDomains$$,totalPoints:$totalPoints$$,originalUrl:$req$$.originalUrl});return{points:$penaltyPoints_trustDomains$$}}
|
|
8
8
|
const createRateLimiterMiddleware=async($blockDuration_config$$,$keyPrefix$$)=>{const $totalPoints$$=$blockDuration_config$$.points||1E3,$duration$$=$blockDuration_config$$.duration||1;$blockDuration_config$$=$blockDuration_config$$.blockDuration||0;const $insuranceLimiter$$=new RateLimiterMemory({points:$totalPoints$$,duration:$duration$$,blockDuration:$blockDuration_config$$}),$limiter$$=new RateLimiterRedis({keyPrefix:$keyPrefix$$,storeClient:global.clientRedis,points:$totalPoints$$,duration:$duration$$,
|
|
9
|
-
blockDuration:$blockDuration_config$$,inMemoryBlockOnConsumed:$totalPoints$$+1,inMemoryBlockDuration:10,insuranceLimiter:$insuranceLimiter$$});return async function($req$$,$res$$,$next$$){let $key$$,$points$$;try{const $origin$$=getOrigin($req$$),$trustKey$$=($req$$.headers["x-trust-key"]||$req$$.query.trustkey||$req$$.query.trust_key||"").toString(),$resolved$$=await resolvePoints($req$$,$origin$$,$trustKey$$,$totalPoints$$,$keyPrefix$$);if($resolved$$.blocked)return $res$$.status(400).send({error:"Access is not allowed"});
|
|
9
|
+
blockDuration:$blockDuration_config$$,inMemoryBlockOnConsumed:$totalPoints$$+1,inMemoryBlockDuration:10,insuranceLimiter:$insuranceLimiter$$});return async function($req$$,$res$$,$next$$){let $key$$,$points$$;try{const $origin$$=getOrigin($req$$),$trustKey$$=($req$$.headers["x-trust-key"]||$req$$.headers["X-Trust-Key"]||$req$$.query.trustkey||$req$$.query.trust_key||"").toString(),$resolved$$=await resolvePoints($req$$,$origin$$,$trustKey$$,$totalPoints$$,$keyPrefix$$);if($resolved$$.blocked)return $res$$.status(400).send({error:"Access is not allowed"});
|
|
10
10
|
$points$$=$resolved$$.points;$key$$=getClientIp($req$$);$req$$.user&&($key$$=`${$key$$}-${$req$$.user.email}`);$key$$=`${$key$$}-${$origin$$||"unknown"}-${$trustKey$$||"untrustkey"}`}catch($e$$){return Logger.error("[rateLimiter] failed to prepare key/points",$keyPrefix$$,$e$$),$next$$()}try{return await $limiter$$.consume($key$$,$points$$),$next$$()}catch($err$$){if($err$$ instanceof Error)return Logger.error("[rateLimiter] infra error",$keyPrefix$$,$err$$),$next$$();$req$$=Math.ceil(($err$$.msBeforeNext||
|
|
11
11
|
1E3)/1E3);$res$$.set("Retry-After",String($req$$));return $res$$.status(429).send({error:"Too Many Requests. Please try again later",retryAfter:$req$$})}}};module.exports={createRateLimiterMiddleware};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
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"),
|
|
2
|
-
|
|
1
|
+
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"),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"),
|
|
2
|
+
{executeInTransaction,runWithoutSession}=require("../libs/sessionContext.js"),importHandler=require("./importHandler"),viewHandler=require("./viewHandler"),{buildJsonSchema}=require("../libs/docs"),{bodyToJson,ERRORS,getNextSequence,asyncPostData,pushNotification,runWebhooks}=require("./controllerUtils"),handlers=require("./handlers");global.__schemaCache=global.__schemaCache||new Map;
|
|
3
3
|
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,onPopulate:void 0}){this.module=this.name=$name$$;this.model=$model$$;this.model_name=$model$$.modelName.toLowerCase();this.router=$router$$;global.controllers[$name$$.trim().toUpperCase()]=this;$options$$.findExact||($options$$.findExact={});this.keyValues=$options$$.keyValues;this.keyValues||(this.keyValues={});$options$$.require_id_app===
|
|
4
4
|
void 0||$options$$.require_id_app===!0?(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.isVoucher=$options$$.isVoucher;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;
|
|
5
5
|
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.populate=$options$$.onPopulate;this.view=$options$$.onView;this.viewRequired=$options$$.onViewRequired;this.cache=$options$$.cache;this.excelParse=$options$$.onExcelParse;this.options=$options$$;this.replaceIfExists=$options$$.replaceIfExists}async getJsonSchema($id_app_schema$$){let $configCacheKey$$=
|
|
6
6
|
`${this.name}_${$id_app_schema$$}`;if(global.__schemaCache&&global.__schemaCache.has($configCacheKey$$)){var $cachedData_listinfo$$=global.__schemaCache.get($configCacheKey$$);if(Date.now()-$cachedData_listinfo$$.timestamp<(global.CONFIG_CACHE_TTL||36E5))return $cachedData_listinfo$$.schema;global.__schemaCache.delete($configCacheKey$$)}$cachedData_listinfo$$=await global.getModel("listinfo").findOne({code:this.name.trim().toLowerCase()}).lean();if(!$cachedData_listinfo$$)return Logger.info("[Controller][getJsonSchema] kh\u00f4ng t\u00ecm th\u1ea5y schema v\u1edbi listinfo_code",
|
|
7
7
|
this.name.trim().toLowerCase()),null;$id_app_schema$$=await buildJsonSchema($cachedData_listinfo$$.fields||[],void 0,$id_app_schema$$);global.__schemaCache.set($configCacheKey$$,{timestamp:Date.now(),schema:$id_app_schema$$});return $id_app_schema$$}async asyncView($user$$,$items$$,$options$$){const $self$$=this;return new Promise($resolve$$=>{$self$$.onView($user$$,$items$$,($error$$,$rs$$)=>{if($error$$)return Logger.error($error$$),$resolve$$($items$$);$resolve$$($rs$$)},$options$$)})}async onView($user$$,
|
|
8
|
-
$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(($
|
|
9
|
-
getNextSequence($id_app$$,$ma_ct$$,$
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
$rs$$})`)
|
|
15
|
-
|
|
16
|
-
$
|
|
17
|
-
$response
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
$
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
$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(async($req$$,$res$$)=>{try{let $id_app$$=$req$$.user.current_id_app,$field$$=$req$$.params.field;if($field$$==="so_ct")return $res$$.send({[$field$$]:$ma_ct$$});
|
|
9
|
+
const $rs$$=await getNextSequence($id_app$$,$ma_ct$$,$field$$);$res$$.send($rs$$)}catch($e$$){return Logger.error("getNextId",$e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})}})}async checkData($appInfo$$,$data$$,$fn$$){const $options$$=this.options;try{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$$&&$tt$$.check_data==0)return $fn$$()}if($data$$.details&&
|
|
10
|
+
$appInfo$$&&$appInfo$$.options&&$appInfo$$.options.khong_xuat_kho_am&&$options$$.check_stock!=0){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||($d$$.combo||[]).length>
|
|
11
|
+
0);$details$$=$details$$.map($detail$$=>$detail$$.combo&&$detail$$.combo.length>0?$detail$$.combo.map($c$$=>{$c$$=$c$$.toObject?utils.convertObjectIdsToStrings($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(),
|
|
12
|
+
id_app:$appInfo$$._id}).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"]);await Promise.all($details$$.map($d$$=>new Promise(($resolve$$,$reject$$)=>{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),
|
|
13
|
+
$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 $reject$$($e$$);if($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)))return $reject$$(`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$$+
|
|
14
|
+
$rs$$})`);$resolve$$()})})))}$fn$$()}catch($e$$){$fn$$($e$$)}}async cacheData($obj$$,$callback$$){$obj$$&&$obj$$.toObject&&($obj$$=utils.convertObjectIdsToStrings($obj$$.toObject()));await redisCache.set(this.model_name,$obj$$,$callback$$)}async deleteData($obj$$,$callback$$){$obj$$&&$obj$$.toObject&&($obj$$=utils.convertObjectIdsToStrings($obj$$.toObject()));await redisCache.remove(this.model_name,$obj$$,$callback$$)}createRoute($routeName$$,$handler_routeAction$$,$_options$$={method:"GET",not_use_worker:!1,
|
|
15
|
+
action_code:"view"}){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$$,headers:$headers$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.ip||$req$$.headers["x-forwarded-for"]||
|
|
16
|
+
$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$$,headers:$headers$$,user_agent:$user_agent$$,ip:$ip$$,files:$files$$,originalUrl:$req$$.originalUrl};global.inputMainPool&&!$_options$$.not_use_worker?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.error||
|
|
17
|
+
$response$$.error.message||$response$$.error,message:$response$$.message||$response$$.error.error||$response$$.error.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;$_options$$.method=="DELETE"?$router$$.route($url$$).delete($handler_routeAction$$):
|
|
18
|
+
$_options$$.method=="POST"?$router$$.route($url$$).post($handler_routeAction$$):$_options$$.method=="PUT"?$router$$.route($url$$).put($handler_routeAction$$):$router$$.route($url$$).get($handler_routeAction$$)}async requestApprove($app_info_listinfo_code$$,$user_request$$,$obj_request$$,$next$$,$str_func$jscomp$2_str_func$$,$preRequest$$){let $ctrl$$=this;if(!$app_info_listinfo_code$$)return $next$$(null,$obj_request$$);let $obj$$;$obj$$=$obj_request$$.toObject?utils.convertObjectIdsToStrings($obj_request$$.toObject()):
|
|
19
|
+
_.cloneDeep($obj_request$$);$obj$$.ma_ct=$obj$$.ma_ct||$ctrl$$.name;let $approveDatas$$=[];$app_info_listinfo_code$$=$obj$$.listinfo_code||$ctrl$$.name;$str_func$jscomp$2_str_func$$||($str_func$jscomp$2_str_func$$=(await OptionsModel.findOne({id_app:$obj$$.id_app,id_func:$app_info_listinfo_code$$},{option:1}).lean()||{}).option);$str_func$jscomp$2_str_func$$&&$str_func$jscomp$2_str_func$$.custom_approve_user&&$str_func$jscomp$2_str_func$$.custom_approve_user.forEach($trang_thai_approve$$=>{let $update_after_approve$$,
|
|
20
|
+
$update_after_deny$$;if($trang_thai_approve$$.update_after_approve)try{let $str_func$$=$trang_thai_approve$$.update_after_approve;$str_func$$.indexOf("return ")<0&&($str_func$$=`return ${$str_func$$}`);$update_after_approve$$=evalute($str_func$$)}catch($e$$){Logger.error("[controller][requestApprove] 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,cho_phep_cap_nhat_khi_da_duyet:$trang_thai_approve$$.cho_phep_cap_nhat_khi_da_duyet,
|
|
21
|
+
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;$str_func$$.indexOf("return ")<0&&($str_func$$=`return ${$str_func$$}`);$update_after_deny$$=evalute($str_func$$)}catch($e$$){Logger.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,
|
|
22
|
+
...(($update_after_deny$$||{}).data||{})}};$approveDatas$$.push($trang_thai_approve$$)});$approveDatas$$=$approveDatas$$.filter($approveData_condition$$=>{$approveData_condition$$=$approveData_condition$$.condition;if(!$approveData_condition$$)return!0;$approveData_condition$$.indexOf("return ")<0&&($approveData_condition$$=`return ${$approveData_condition$$}`);try{return evalute($approveData_condition$$,{master:$obj$$,data:$obj$$})}catch($e$$){return Logger.error("check condition approve",$e$$,$approveData_condition$$),
|
|
23
|
+
!1}});try{for(let $approveData$$ of $approveDatas$$.filter($a$$=>$a$$.approve_users||$a$$.approve_users_custom||$a$$.approve_phu_trach_bp)){let $title$$=$approveData$$.title||"Y\u00eau c\u1ea7u duy\u1ec7t";if($title$$.indexOf("return ")>=0){$str_func$jscomp$2_str_func$$=$title$$;try{$title$$=evalute($str_func$jscomp$2_str_func$$,{master:$obj$$,data:$obj$$})}catch($e$$){Logger.error("request approve",$e$$,$str_func$jscomp$2_str_func$$)}}let $ds_nguoi_duyet$$=$approveData$$.approve_users,$update_after_approve$$=
|
|
24
|
+
$approveData$$.update_after_approve,$update_after_deny$$=$approveData$$.update_after_deny;if(_.isString($ds_nguoi_duyet$$))try{if($str_func$jscomp$2_str_func$$=$ds_nguoi_duyet$$,$str_func$jscomp$2_str_func$$.indexOf("return ")<0&&($str_func$jscomp$2_str_func$$=`return ${$str_func$jscomp$2_str_func$$}`),$ds_nguoi_duyet$$=evalute($str_func$jscomp$2_str_func$$,{master:$obj$$,data:$obj$$,preRequest:$preRequest$$}),!_.isArray($ds_nguoi_duyet$$)){Logger.error("danh s\u00e1ch ng\u01b0\u1eddi duy\u1ec7t ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng, hi\u1ec7n t\u1ea1i \u0111ang l\u00e0",
|
|
25
|
+
$ds_nguoi_duyet$$);return}}catch($e$$){Logger.error("request approve",$e$$,$ds_nguoi_duyet$$);return}if($approveData$$.approve_phu_trach_bp&&$obj$$.ma_nv){let $nv$$=await global.getModel("dmnv").findOne({id_app:$obj$$.id_app,ma_nv:$obj$$.ma_nv},{ma_bp:1}).lean();if($nv$$?.ma_bp){let $bp$$=await global.getModel("dmbp").findOne({id_app:$obj$$.id_app,ma_bp:$nv$$?.ma_bp},{phu_trach:1}).lean();$bp$$?.phu_trach&&$ds_nguoi_duyet$$.push($bp$$?.phu_trach)}}if($approveData$$.approve_users_custom)try{let $str_func$$=
|
|
26
|
+
$approveData$$.approve_users_custom;$str_func$$.indexOf("return ")<0&&($str_func$$=`return ${$str_func$$}`);let $ds_nguoi_duyet_custom$$=await evalute(`return (async ()=>{
|
|
27
27
|
try{
|
|
28
28
|
${$str_func$$}
|
|
29
29
|
}catch(e){
|
|
@@ -32,24 +32,24 @@ if($nv$$?.ma_bp){let $bp$$=await global.getModel("dmbp").findOne({id_app:$obj$$.
|
|
|
32
32
|
})`,{master:$obj$$,data:$obj$$,preRequest:$preRequest$$,utils})();$ds_nguoi_duyet_custom$$&&(_.isArray($ds_nguoi_duyet_custom$$)?$ds_nguoi_duyet$$=[...$ds_nguoi_duyet$$,...$ds_nguoi_duyet_custom$$]:Logger.error("[controller][requestapprove] 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$$){Logger.error("[controller][requestapprove] ",$e$$,$approveData$$.approve_users_custom)}Logger.info("[controller][requestapprove] Danh sach ng\u01b0\u1eddi duy\u1ec7t \u0111\u1ea7y \u0111\u1ee7",
|
|
33
33
|
$ds_nguoi_duyet$$);if($ds_nguoi_duyet$$&&$ds_nguoi_duyet$$.length!==0&&($ds_nguoi_duyet$$=[...(new Set($ds_nguoi_duyet$$))],$obj$$.trang_thai==$approveData$$.trang_thai)){let $user_approves$$=$ds_nguoi_duyet$$.map($nguoi_duyet$$=>({email:$nguoi_duyet$$,name:$nguoi_duyet$$}));await $user_approves$$.asyncJoinModel2($obj$$.id_app,Participant,{where:"email",fields:"name"});await [$user_request$$].asyncJoinModel2($obj$$.id_app,Participant,{where:"email",fields:"name"});await new Promise(($resolve$$,$reject$$)=>
|
|
34
34
|
{Approve.request($user_request$$,$user_approves$$,$title$$,$obj$$,$e$$=>{if($e$$)return $reject$$($e$$);$resolve$$()},$update_after_approve$$,$approveData$$.template_content,$update_after_deny$$)})}}$next$$(null,$obj$$)}catch($e$$){$next$$($e$$)}}async import($user$$,$id_app$$,$data$$,$callback_main$$,$options$$={replace:!0,req:null,listinfo_code:null}){importHandler($user$$,this,$id_app$$,$data$$,$callback_main$$,$options$$)}pushNotification($_obj$$,$eventName$$="new",$old_obj$$=null,$justFireEvents$$=
|
|
35
|
-
!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$$)=>
|
|
36
|
-
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{(await permission.getFieldNotRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.name)).indexOf($fieldName$$)>=0?$res$$.send({allow:!1}):$res$$.send({allow:!0})}catch($e$$){$res$$.
|
|
35
|
+
!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$$)=>getNextSequence($id_app$$,$ma_ct$$,$field$$,$options$$);
|
|
36
|
+
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{(await permission.getFieldNotRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.name)).indexOf($fieldName$$)>=0?$res$$.send({allow:!1}):$res$$.send({allow:!0})}catch($e$$){$res$$.status(400).send($e$$.message)}})};
|
|
37
37
|
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$$;$dataType$$=="xlsx"?($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$$,
|
|
38
38
|
body:$body$$,user:$user$$,params:$params$$,headers:$headers$$,protocol:$protocol$$}=$ip$jscomp$1_req$$;var $_req$$=configs?.api_url||$ip$jscomp$1_req$$.get("hostName");const $user_agent$$=$ip$jscomp$1_req$$.header("user-agent");$ip$jscomp$1_req$$=$ip$jscomp$1_req$$.ip||$ip$jscomp$1_req$$.headers["x-forwarded-for"]||$ip$jscomp$1_req$$.connection.remoteAddress;try{if($_req$$={handler:"findHandler",protocol:$protocol$$,host:$_req$$,query:$query$$,body:$body$$,user:$user$$,params:$params$$,headers:$headers$$,
|
|
39
39
|
user_agent:$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$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$response$$=>{if($response$$.error)return $res$$.status(400).send({error:$response$$.error.error||$response$$.error.message||$response$$.error,message:$response$$.message||$response$$.error.error||$response$$.error.message||
|
|
40
40
|
$response$$.error,code:$response$$.code});$handlerResult$$($res$$,$response$$.result)})}else handlers.findHandler($ctrl$$,$_req$$,($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;$method$$==="GET"?(this.router.route($_route_name_route_name$$).get($findRoute$$),this.router.route($_route_name_route_name$$+"/excel").get($findRoute$$)):
|
|
41
41
|
(this.router.route($_route_name_route_name$$).post($findRoute$$),this.router.route($_route_name_route_name$$+"/excel").post($findRoute$$))};
|
|
42
42
|
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$$){let $id$$=$req$$.params.id;if(!global.mongoose.Types.ObjectId.isValid($id$$))return $res$$.status(404).send({error:ERRORS.ERR_ID_INVALID,code:ERRORS.ERR_ID_INVALID_CODE});let $body$$={_id:$id$$};const $user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress,
|
|
43
|
-
{query:$query$$,user:$user$$,params:$params$$,headers:$headers$$}=$req$$;if($ctrl$$.getting)try{await new Promise(($resolve$$,$reject$$)=>{$ctrl$$.getting($user$$,$id$$,$e$$=>{if($e$$)return $reject$$($e$$);$resolve$$()})})}catch($e$$){return $res$$.status(400).send($e$$)}try{handlers.findHandler($ctrl$$,{query:$query$$,body:$body$$,user:$user$$,params:$params$$,headers:$headers$$,user_agent:$user_agent$$,ip:$ip$$,shareRoute:$shareRoute$$,originalUrl:$req$$.originalUrl},($e$jscomp$
|
|
44
|
-
{if($e$jscomp$
|
|
43
|
+
{query:$query$$,user:$user$$,params:$params$$,headers:$headers$$}=$req$$;if($ctrl$$.getting)try{await new Promise(($resolve$$,$reject$$)=>{$ctrl$$.getting($user$$,$id$$,$e$$=>{if($e$$)return $reject$$($e$$);$resolve$$()})})}catch($e$$){return $res$$.status(400).send($e$$)}try{handlers.findHandler($ctrl$$,{query:$query$$,body:$body$$,user:$user$$,params:$params$$,headers:$headers$$,user_agent:$user_agent$$,ip:$ip$$,shareRoute:$shareRoute$$,originalUrl:$req$$.originalUrl},($e$jscomp$18_result$$,$returnvalue$$)=>
|
|
44
|
+
{if($e$jscomp$18_result$$)return $res$$.status(400).send($e$jscomp$18_result$$);({result:$e$jscomp$18_result$$}=$returnvalue$$);if($e$jscomp$18_result$$.length==0)return $res$$.status(404).send({error:ERRORS.ERR_NOT_FOUND,code:ERRORS.ERR_NOT_FOUND_CODE});$res$$.send($e$jscomp$18_result$$[0])})}catch($e$$){Logger.error($e$$),$res$$.status(400).send($e$$)}})};
|
|
45
45
|
controller.prototype.postAgainHandler=async function($user$$,$condition$$,$callback$$,$options$$={req:null}){let $model$$=this.model,$ctrl$$=this;if(!$ctrl$$.post)return $callback$$(null,{message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 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},$objsrepost$$=await $model$$.find($condition$$).sort({ngay_ct:1}).lean();Logger.info("[postagain] start repost",
|
|
46
|
-
$condition$$,$objsrepost$$.length," vouchers","by",$user$$.email);
|
|
47
|
-
|
|
48
|
-
$
|
|
49
|
-
|
|
46
|
+
$condition$$,$objsrepost$$.length," vouchers","by",$user$$.email);try{for(const $obj$$ of $objsrepost$$)await runWithoutSession(async()=>{await executeInTransaction(async()=>{Logger.info("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$$){throw{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+
|
|
47
|
+
", L\u1ed7i: "+($e$$.message||$e$$.error||"")};}$update_tk_vt$$&&$obj$$.details&&(Logger.info("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{Logger.info("postAgain: update voucher..."),await $model$$.updateOne({_id:$obj$$._id},{...$user_update$$})}catch($e$$){throw Logger.error("postAgain: error update data before repost",$e$$),{error:"Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u01b0\u1ee3c d\u1eef li\u1ec7u ch\u1ee9ng t\u1eeb "+
|
|
48
|
+
$obj$$.so_ct+",Error:"+$e$$.message||$e$$.error||""};}try{await asyncPostData($obj$$,$ctrl$$,{req:$options$$.req,kiem_tra_han_muc_cong_no:!1})}catch($e$$){throw{error:$e$$.message||$e$$.error||"Kh\u00f4ng th\u1ec3 post s\u1ed5 s\u00e1ch ch\u1ee9ng t\u1eeb:"+$obj$$.so_ct};}})})}catch($e$$){return Logger.error("[postAgain]: Error",$e$$),$callback$$({error:$e$$.message||$e$$.error||$e$$})}Logger.info("postAgain: finished",$condition$$,$objsrepost$$.length," vouchers","by",$user$$.email);$callback$$(null,
|
|
49
|
+
{message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n xong"})};
|
|
50
50
|
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$$,headers:$headers$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{const $_req$$={handler:"updateBookHandler",query:$query$$,body:$body$$,user:$user$$,params:$params$$,headers:$headers$$,
|
|
51
51
|
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")}`,$status_task$$=`${configs.api_url||configs.domain}/task-status/${$id_task$$}`;$res$$.status(202).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:$status_task$$});
|
|
52
|
-
global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$e$jscomp$
|
|
52
|
+
global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$e$jscomp$24_response$$=>{if($e$jscomp$24_response$$=$e$jscomp$24_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$24_response$$.message||$e$jscomp$24_response$$.error||$e$jscomp$24_response$$,null,{id_app:$req$$.user.current_id_app},
|
|
53
53
|
!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$$.status(202).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"}),
|
|
54
54
|
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",
|
|
55
55
|
null,{id_app:$req$$.user.current_id_app},!0,$req$$.access_token,!0)})}catch($e$$){$res$$.status(400).send($e$$)}})};
|
|
@@ -65,22 +65,22 @@ params:$params$$,headers:$headers$$,user_agent:$user_agent$$,ip:$ip$$,originalUr
|
|
|
65
65
|
$response$$?.result?.ext);$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$$)}};this.router.route(`${this.route_name}/excel/:rpt_id`).get($handleRoute$$);this.router.route(`${this.route_name}/export/:rpt_id`).get($handleRoute$$)};
|
|
66
66
|
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$$,headers:$headers$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{const $_req$$={handler:"importFromGsHandler",query:$query$$,body:$body$$,user:$user$$,params:$params$$,headers:$headers$$,
|
|
67
67
|
user_agent:$user_agent$$,ip:$ip$$,originalUrl:$req$$.originalUrl};if(global.importDataMainPool){const $id_task$$=`task-import-google-sheet-${crypto.randomBytes(20).toString("hex")}`,$status_task$$=`${configs.api_url||configs.domain}/task-status/${$id_task$$}`;$_req$$.status_task=$status_task$$;$res$$.status(202).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",
|
|
68
|
-
status_task:$status_task$$});global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$e$jscomp$
|
|
69
|
-
$e$jscomp$
|
|
68
|
+
status_task:$status_task$$});global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$e$jscomp$33_response$$=>{if($e$jscomp$33_response$$=$e$jscomp$33_response$$.error)return Logger.error("\u274c [importFromGoogleSheet] l\u1ed7i",$e$jscomp$33_response$$),global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$jscomp$33_response$$.message||$e$jscomp$33_response$$.error||
|
|
69
|
+
$e$jscomp$33_response$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);Logger.info("\u2705[importFromGoogleSheet] \u0111\u00e3 import ho\u00e0n th\u00e0nh. G\u1eedi th\u00f4ng b\u00e1o t\u1edbi ng\u01b0\u1eddi th\u1ef1c hi\u1ec7n");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},
|
|
70
70
|
!0,null,!0)},1728E5)}else $res$$.status(202).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 Logger.error("\u274c [importFromGoogleSheet] l\u1ed7i",$e$$),global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$$.message||
|
|
71
71
|
$e$$.error||$e$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);Logger.info("\u2705[importFromGoogleSheet] \u0111\u00e3 import ho\u00e0n th\u00e0nh. G\u1eedi th\u00f4ng b\u00e1o t\u1edbi ng\u01b0\u1eddi th\u1ef1c hi\u1ec7n");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},
|
|
72
72
|
!0,null,!0)})}catch($e$$){$res$$.status(400).send($e$$)}})};
|
|
73
73
|
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$$,headers:$headers$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{const $_req$$={handler:"importFromJsonHandler",query:$query$$,body:$body$$,user:$user$$,params:$params$$,headers:$headers$$,
|
|
74
74
|
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")}`,$status_task$$=`${configs.api_url||configs.domain}/task-status/${$id_task$$}`;$_req$$.status_task=$status_task$$;$res$$.status(202).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",
|
|
75
|
-
status_task:$status_task$$});global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$e$jscomp$
|
|
76
|
-
$e$jscomp$
|
|
75
|
+
status_task:$status_task$$});global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$e$jscomp$36_response$$=>{if($e$jscomp$36_response$$=$e$jscomp$36_response$$.error)return Logger.error("\u274c [importFromJson] l\u1ed7i",$e$jscomp$36_response$$),global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$jscomp$36_response$$.message||$e$jscomp$36_response$$.error||
|
|
76
|
+
$e$jscomp$36_response$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);Logger.info("\u2705[importFromJson] \u0111\u00e3 import ho\u00e0n th\u00e0nh. G\u1eedi th\u00f4ng b\u00e1o t\u1edbi ng\u01b0\u1eddi th\u1ef1c hi\u1ec7n");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},
|
|
77
77
|
!0,null,!0)},1728E5)}else $res$$.status(202).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 Logger.error("\u274c [importFromJson] l\u1ed7i",$e$$),global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$$.message||
|
|
78
78
|
$e$$.error||$e$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);Logger.info("\u2705[importFromJson] \u0111\u00e3 import ho\u00e0n th\u00e0nh. G\u1eedi th\u00f4ng b\u00e1o t\u1edbi ng\u01b0\u1eddi th\u1ef1c hi\u1ec7n");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,
|
|
79
79
|
null,!0)})}catch($e$$){Logger.error("Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$$),$res$$.status(400).send($e$$)}})};
|
|
80
80
|
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$$,headers:$headers$$,files:$files$$}=$req$$,$user_agent$$=$req$$.header("user-agent"),$ip$$=$req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress;try{const $_req$$={handler:"importFromExcelHandler",query:$query$$,body:$body$$,user:$user$$,params:$params$$,headers:$headers$$,
|
|
81
81
|
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")}`,$status_task$$=`${configs.api_url||configs.domain}/task-status/${$id_task$$}`;$_req$$.status_task=$status_task$$;$res$$.status(202).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",
|
|
82
|
-
status_task:$status_task$$});global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$e$jscomp$
|
|
83
|
-
$e$jscomp$
|
|
82
|
+
status_task:$status_task$$});global.importDataMainPool.exec({id_task:$id_task$$,req:$_req$$,module:$ctrl$$.name.toUpperCase(),configs:JSON.stringify(configs)},$e$jscomp$39_response$$=>{if($e$jscomp$39_response$$=$e$jscomp$39_response$$.error)return Logger.error("\u274c [importFromExcel] l\u1ed7i",$e$jscomp$39_response$$),global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$jscomp$39_response$$.message||$e$jscomp$39_response$$.error||
|
|
83
|
+
$e$jscomp$39_response$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);Logger.info("\u2705[importFromExcel] \u0111\u00e3 import ho\u00e0n th\u00e0nh. G\u1eedi th\u00f4ng b\u00e1o t\u1edbi ng\u01b0\u1eddi th\u1ef1c hi\u1ec7n");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},
|
|
84
84
|
!0,null,!0)},1728E5)}else $res$$.status(202).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 Logger.error("\u274c [importFromExcel] l\u1ed7i",$e$$),global.getModel("notification").createNotification($req$$.user.email,$req$$.user.email,"Kh\u00f4ng th\u1ec3 import d\u1eef li\u1ec7u",$e$$.message||
|
|
85
85
|
$e$$.error||$e$$,null,{id_app:$req$$.user.current_id_app},!0,null,!0);Logger.info("\u2705[importFromExcel] \u0111\u00e3 import ho\u00e0n th\u00e0nh. G\u1eedi th\u00f4ng b\u00e1o t\u1edbi ng\u01b0\u1eddi th\u1ef1c hi\u1ec7n");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,
|
|
86
86
|
null,!0)})}catch($e$$){$res$$.status(400).send($e$$)}})};
|
|
@@ -113,14 +113,14 @@ controller.prototype.asyncPostData=function($obj$$,$options$$={}){Logger.info("[
|
|
|
113
113
|
controller.prototype.route=function($setRoute$$){configs.lite||(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(),
|
|
114
114
|
$setRoute$$&&$setRoute$$(this.router))};
|
|
115
115
|
controller.prototype.findData=async function($user$$,$condition$$,$options$$={limit:20,page:1,fields:void 0,sort:void 0,pagination:0,count:0,"listinfo-code":void 0},$req$$,$callback$$){const $ctrl$$=this;$req$$=$req$$||{};$req$$.query=$req$$.query||{};$options$$.fields&&typeof $options$$.fields=="object"&&!Array.isArray($options$$.fields)&&($options$$.fields=Object.keys($options$$.fields));$req$$.body={q:$condition$$,...$options$$};try{const $result$$=await new Promise(($resolve$$,$reject$$)=>{let $id_app$$=
|
|
116
|
-
$req$$.query.id_app||$condition$$.id_app;if($ctrl$$.require_id_app&&!$id_app$$)return $reject$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u \u0111i\u1ec1u ki\u1ec7n id_app");typeof $user$$==="string"&&($user$$={email:$user$$});$user$$.current_id_app||($user$$.current_id_app=$id_app$$);!$user$$.current_app_info&&$user$$.current_id_ap&&($user$$.current_app_info={_id:$user$$.current_id_ap,name:$user$$.current_id_ap});$req$$.user=$user$$;handlers.findHandler($ctrl$$,$req$$,($e$jscomp$
|
|
117
|
-
$returnvalue$$)=>{if($e$jscomp$
|
|
116
|
+
$req$$.query.id_app||$condition$$.id_app;if($ctrl$$.require_id_app&&!$id_app$$)return $reject$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u \u0111i\u1ec1u ki\u1ec7n id_app");typeof $user$$==="string"&&($user$$={email:$user$$});$user$$.current_id_app||($user$$.current_id_app=$id_app$$);!$user$$.current_app_info&&$user$$.current_id_ap&&($user$$.current_app_info={_id:$user$$.current_id_ap,name:$user$$.current_id_ap});$req$$.user=$user$$;handlers.findHandler($ctrl$$,$req$$,($e$jscomp$58_result$$,
|
|
117
|
+
$returnvalue$$)=>{if($e$jscomp$58_result$$)return $reject$$($e$jscomp$58_result$$);({result:$e$jscomp$58_result$$}=$returnvalue$$);$resolve$$($e$jscomp$58_result$$)})});return $callback$$&&typeof $callback$$=="function"?$callback$$(null,$result$$):$result$$}catch($e$$){if($callback$$&&typeof $callback$$=="function")return $callback$$($e$$);throw $e$$;}};controller.runWebhooks=runWebhooks;
|
|
118
118
|
controller.postData=async function($obj$$,$ctrl$$,$cb$$,$options$$={}){Logger.info("[controller] postData",this.name);try{let $rs$$=await executeInTransaction(async()=>await asyncPostData($obj$$,$ctrl$$,$options$$),{useParent:!0});$cb$$(null,$rs$$)}catch($e$$){$cb$$($e$$)}};controller.asyncPostData=async function($obj$$,$ctrl$$,$options$$={}){Logger.info("[controller] asyncPostData",this.name);return executeInTransaction(async()=>await asyncPostData($obj$$,$ctrl$$,$options$$),{useParent:!0})};
|
|
119
119
|
controller.pushNotification=pushNotification;
|
|
120
|
-
controller.create=async function($user$$,$ctrl$$,$data$$,$callback$$,$id_be_supply_by_user$$,$req$$,$action$$="add"){$req$$=$req$$||{};$req$$.query=$req$$.query||{};$req$$.user=$user$$;$req$$.data=$data$$;$req$$.id_be_supply_by_user=$id_be_supply_by_user$$;$req$$.action=$action$$;try{const $result$$=await new Promise(($resolve$$,$reject$$)=>{handlers.createHandler($ctrl$$,$req$$,($e$jscomp$
|
|
121
|
-
$returnvalue$$);pushNotification($ctrl$$,$e$jscomp$
|
|
120
|
+
controller.create=async function($user$$,$ctrl$$,$data$$,$callback$$,$id_be_supply_by_user$$,$req$$,$action$$="add"){$req$$=$req$$||{};$req$$.query=$req$$.query||{};$req$$.user=$user$$;$req$$.data=$data$$;$req$$.id_be_supply_by_user=$id_be_supply_by_user$$;$req$$.action=$action$$;try{const $result$$=await new Promise(($resolve$$,$reject$$)=>{handlers.createHandler($ctrl$$,$req$$,($e$jscomp$61_obj_created$$,$returnvalue$$)=>{if($e$jscomp$61_obj_created$$)return $reject$$($e$jscomp$61_obj_created$$);({obj_created:$e$jscomp$61_obj_created$$}=
|
|
121
|
+
$returnvalue$$);pushNotification($ctrl$$,$e$jscomp$61_obj_created$$,"new",null,null,{exclude_token:($req$$.query||{}).access_token});$resolve$$($e$jscomp$61_obj_created$$)})});return $callback$$&&typeof $callback$$=="function"?$callback$$(null,$result$$):$result$$}catch($e$$){if($callback$$&&typeof $callback$$=="function")return $callback$$($e$$);throw $e$$;}};
|
|
122
122
|
controller.prototype.createData=async function($user$$,$data$$,$callback$$,$req$$,$action$$="add"){const $ctrl$$=this;$req$$=$req$$||{};$req$$.query=$req$$.query||{};$req$$.user=$user$$;$req$$.data=$data$$;$req$$.action=$action$$;try{const $result$$=await new Promise(($resolve$$,$reject$$)=>{let $id_app$$=$req$$.query.id_app||$data$$.id_app;if($ctrl$$.require_id_app&&!$id_app$$)return $reject$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u id_app");typeof $user$$==="string"&&($user$$={email:$user$$});
|
|
123
|
-
$user$$.current_id_app||($user$$.current_id_app=$id_app$$);!$user$$.current_app_info&&$user$$.current_id_ap&&($user$$.current_app_info={_id:$user$$.current_id_ap,name:$user$$.current_id_ap});$req$$.user=$user$$;handlers.createHandler($ctrl$$,$req$$,($e$jscomp$
|
|
123
|
+
$user$$.current_id_app||($user$$.current_id_app=$id_app$$);!$user$$.current_app_info&&$user$$.current_id_ap&&($user$$.current_app_info={_id:$user$$.current_id_ap,name:$user$$.current_id_ap});$req$$.user=$user$$;handlers.createHandler($ctrl$$,$req$$,($e$jscomp$63_obj_created$$,$returnvalue$$)=>{if($e$jscomp$63_obj_created$$)return $reject$$($e$jscomp$63_obj_created$$);({obj_created:$e$jscomp$63_obj_created$$}=$returnvalue$$);pushNotification($ctrl$$,$e$jscomp$63_obj_created$$,"new",null,null);$resolve$$($e$jscomp$63_obj_created$$)})});
|
|
124
124
|
return $callback$$&&typeof $callback$$=="function"?$callback$$(null,$result$$):$result$$}catch($e$$){if($callback$$&&typeof $callback$$=="function")return $callback$$($e$$);throw $e$$;}};
|
|
125
125
|
controller.prototype.updateData=async function($user$$,$_id$$,$data$$,$callback$$,$req$$,$action$$="update"){const $ctrl$$=this;$req$$=$req$$||{};$req$$.query=$req$$.query||{};$req$$.user=$user$$;$req$$.data=$data$$;$req$$.action=$action$$;$req$$._action=$action$$;$req$$.id=$_id$$;try{const $result$$=await new Promise(($resolve$$,$reject$$)=>{let $id_app$$=$req$$.query.id_app||$data$$.id_app;if($ctrl$$.require_id_app&&!$id_app$$)return $reject$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u id_app");
|
|
126
126
|
typeof $user$$==="string"&&($user$$={email:$user$$});$user$$.current_id_app||($user$$.current_id_app=$id_app$$);!$user$$.current_app_info&&$user$$.current_id_ap&&($user$$.current_app_info={_id:$user$$.current_id_ap,name:$user$$.current_id_ap});$req$$.user=$user$$;handlers.updateHandler($ctrl$$,$req$$,($e$$,$returnvalue$$)=>{if($e$$)return $reject$$($e$$);let {new_obj:$new_obj$$,old_obj:$old_obj$$}=$returnvalue$$;pushNotification($ctrl$$,$new_obj$$,$action$$,$old_obj$$,null);$resolve$$($new_obj$$)})});
|