flexbiz-server 12.6.3 → 12.6.5
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 +2 -2
- package/server/auths/authMiddleware.js +3 -0
- package/server/auths/bearer.js +2 -2
- package/server/auths/local.js +22 -22
- package/server/controllers/controller.js +1 -1
- package/server/controllers/controllerRPT.js +2 -2
- package/server/controllers/createHandler.js +14 -14
- package/server/controllers/createRouteHandler.js +1 -1
- package/server/controllers/rptCreateRouteHandler.js +1 -1
- package/server/libs/databanletheongay.js +21 -19
- package/server/libs/permission.js +29 -28
- package/server/libs/tinhgiatb.js +30 -561
- package/server/libs/tinhgiatb1vt.js +7 -153
- package/server/libs/tinhgiatb1vt_old.js +5 -0
- package/server/libs/vsocai.js +11 -211
- package/server/libs/vsocai_old.js +2 -2
- package/server/models/app.js +15 -283
- package/server/models/bangtinhluong.js +4 -4
- package/server/models/bds_nhadat_moigioi_ban.js +3 -0
- package/server/models/listinfo.js +1 -0
- package/server/models/pc1.js +1 -1
- package/server/models/pt1.js +1 -1
- package/server/models/tdttco.js +4 -3
- package/server/models/tdttco_tt.js +3 -3
- package/server/models/tdttno.js +4 -3
- package/server/models/tdttno_tt.js +4 -4
- package/server/models/tokens.js +2 -1
- package/server/models/user.js +5 -5
- package/server/modules/lists/ls-bds_nhadat.js +10 -9
- package/server/modules/lists/ls-bds_nhadat_moigioi_ban.js +7 -0
- package/server/modules/lists/ls-customer.js +23 -408
- package/server/modules/lists/ls-dmvt.js +70 -1232
- package/server/modules/lists/ls-introducer.js +20 -19
- package/server/modules/lists/ls-productcode.js +3 -3
- package/server/modules/reports/calc-tinhluong.js +21 -21
- package/server/modules/reports/rp-chitietchitientheohoadon.js +4 -4
- package/server/modules/reports/rp-chitietthutientheohoadon.js +3 -3
- package/server/modules/reports/rp-phanbochitienchohoadon.js +4 -4
- package/server/modules/reports/rp-phanbothutienchohoadon.js +3 -3
- package/server/modules/vouchers/vo-bc1.js +10 -9
- package/server/modules/vouchers/vo-bn1.js +17 -16
- package/server/modules/vouchers/vo-hd1.js +1 -1
- package/server/modules/vouchers/vo-hd2.js +6 -6
- package/server/modules/vouchers/vo-pbl.js +2 -2
- package/server/modules/vouchers/vo-pc1.js +26 -25
- package/server/modules/vouchers/vo-pt1.js +7 -6
- package/server/route.js +13 -13
- package/server/workers/pushNotify.js +3 -3
- package/server/workers/sendEmail.js +11 -10
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.6.
|
|
5
|
+
"version": "12.6.5",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Van Truong Pham",
|
|
8
8
|
"email": "invncur@gmail.com"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dynamic-watermark": "^1.0.0",
|
|
32
32
|
"ejs": "^4.0.1",
|
|
33
33
|
"elliptic-nodejs": "^6.5.4",
|
|
34
|
-
"excel-report": "^1.0.
|
|
34
|
+
"excel-report": "^1.0.3",
|
|
35
35
|
"expo-server-sdk": "^3.6.0",
|
|
36
36
|
"express": "^4.17.1",
|
|
37
37
|
"express-session": "^1.17.2",
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const passport=require("passport");
|
|
2
|
+
module.exports=function($req$$,$res$$,$next$$){passport.authenticate("bearer",{session:!1},function($err_errorMatch_errorMessage$$,$match_user$$,$info$$){if($err_errorMatch_errorMessage$$)return $res$$.status(500).json({error:$err_errorMatch_errorMessage$$.message||$err_errorMatch_errorMessage$$||"Internal Server Error",code:500});if(!$match_user$$)return $err_errorMatch_errorMessage$$="Unauthorized",typeof $info$$==="string"?($match_user$$=$info$$.match(/error_description="([^"]+)"/))&&$match_user$$[1]?
|
|
3
|
+
$err_errorMatch_errorMessage$$=$match_user$$[1]:$info$$.includes('error="')&&($err_errorMatch_errorMessage$$=($err_errorMatch_errorMessage$$=$info$$.match(/error="([^"]+)"/))?$err_errorMatch_errorMessage$$[1]:$info$$):$info$$&&$info$$.message&&($err_errorMatch_errorMessage$$=$info$$.message),$res$$.status(401).json({error:$err_errorMatch_errorMessage$$,code:401});$req$$.user=$match_user$$;$next$$()})($req$$,$res$$,$next$$)};
|
package/server/auths/bearer.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
const User=global.getModel("user"),BearerStrategy=require("passport-http-bearer").Strategy;
|
|
2
|
-
module.exports=function($passport$$){$passport$$.use(new BearerStrategy({passReqToCallback:!0},function($req$$,$token$$,$done$$){let $ip$$=$req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress,$session_created$$=($req$$.cookies||{}).uid;setImmediate(function(){User.findByToken($token$$,$ip$$,async function($err$$,$user$$,$tokenInfo$$){if($err$$)return $done$$(
|
|
3
|
-
$done$$("Token
|
|
2
|
+
module.exports=function($passport$$){$passport$$.use(new BearerStrategy({passReqToCallback:!0},function($req$$,$token$$,$done$$){let $ip$$=$req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress,$session_created$$=($req$$.cookies||{}).uid;setImmediate(function(){User.findByToken($token$$,$ip$$,async function($err$$,$user$$,$tokenInfo$$){if($err$$)return $done$$(null,!1,{message:$err$$});if($tokenInfo$$&&$tokenInfo$$.once&&$tokenInfo$$.used)return $done$$(null,!1,{message:"Token n\u00e0y \u0111\u00e3 h\u1ebft hi\u1ec7u l\u1ef1c"});
|
|
3
|
+
if(!$user$$)return $done$$(null,!1,{message:"Token kh\u00f4ng h\u1ee3p l\u1ec7"});if($user$$.status==0)return $done$$(null,!1,{message:"T\u00e0i kho\u1ea3n n\u00e0y kh\u00f4ng c\u00f2n hi\u1ec7u l\u1ef1c"});$user$$.toObject&&($user$$=$user$$.toObject());$user$$.token_id_app=$tokenInfo$$.only_id_app;$user$$.token_id_apps=$tokenInfo$$.id_apps;return $done$$(null,$user$$)},{session_created:$session_created$$})})}))};
|
package/server/auths/local.js
CHANGED
|
@@ -3,7 +3,7 @@ OTP=global.getModel("otp"),DIGITS="0123456789",jwt=require("jsonwebtoken"),redis
|
|
|
3
3
|
function generateToken($accessToken_user$$){var $body_n$$={email:$accessToken_user$$.email};configs.APP_SECRET?$accessToken_user$$=jwt.sign({user:$body_n$$},configs.APP_SECRET):($body_n$$=new Date,$accessToken_user$$=_crypto.createHash("md5").update($accessToken_user$$.email+$body_n$$.toISOString()).digest("hex"));return $accessToken_user$$}
|
|
4
4
|
function saveOTP($Phone$$,$otp_code$$,$expires$$=5){let $expire_time$$=new Date;$expire_time$$.setMinutes($expire_time$$.getMinutes()+$expires$$);return OTP.create({phone:$Phone$$,otp:$otp_code$$,expire_time:$expire_time$$})}
|
|
5
5
|
function findByUsername($username$$,$fn$$){if(!$username$$)return $fn$$("B\u1ea1n ch\u01b0a nh\u1eadp t\u00e0i kho\u1ea3n");User.findOne({$or:[{email:$username$$},{"local.phone":$username$$}]},function($error$$,$result$$){return!$error$$&&$result$$&&$result$$.local?$fn$$(null,$result$$):$fn$$($error$$||`T\u00e0i kho\u1ea3n ${$username$$} kh\u00f4ng t\u1ed3n t\u1ea1i`)})}
|
|
6
|
-
async function addUserToApp($user$$,$body$$,$par_session_created_ug$$){if($body$$.id_app){if(!await App.findById($body$$.id_app))throw Logger.error("Can't find app",$body$$.id_app),"Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y th\u00f4ng tin c\u00f4ng ty n\u00e0y";$user$$.current_id_app=$body$$.id_app;$par_session_created_ug$$=await Participant.asyncCreateParticipant({id_app:$body$$.id_app,name:$body$$.name||$user$$.email,email:$body$$.email,group_id:$body$$.group_id,active:!0,session_created:$par_session_created_ug$$});
|
|
6
|
+
async function addUserToApp($user$$,$body$$,$par_session_created_ug$$){if($body$$.id_app){if(!await App.findById($body$$.id_app))throw Logger.error("[addUserToApp] Can't find app",$body$$.id_app),"Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y th\u00f4ng tin c\u00f4ng ty n\u00e0y";$user$$.current_id_app=$body$$.id_app;$par_session_created_ug$$=await Participant.asyncCreateParticipant({id_app:$body$$.id_app,name:$body$$.name||$user$$.email,email:$body$$.email,group_id:$body$$.group_id,active:!0,session_created:$par_session_created_ug$$});
|
|
7
7
|
let $cust$$;await global.getModel("customer").findOne({id_app:$body$$.id_app,of_user:$user$$.email},{_id:1}).lean()||($cust$$={ten_kh:$body$$.name||$user$$.email,email:validator.isEmail($user$$.email)?$user$$.email:void 0},$body$$.customer_info&&($cust$$={...$cust$$,...$body$$.customer_info}),$cust$$.ten_kh||($cust$$.ten_kh=$body$$.name||$user$$.email),$cust$$={...$cust$$,id_app:$body$$.id_app,user_created:$user$$.email,user_updated:$user$$.email,kh_yn:!0,of_user:$user$$.email},$par_session_created_ug$$&&
|
|
8
8
|
$par_session_created_ug$$.group_id&&($par_session_created_ug$$=await global.getModel("usergroup").findOne({id_app:$body$$.id_app,_id:$par_session_created_ug$$.group_id},{nh_kh:1}),$cust$$.nh_kh=($par_session_created_ug$$||{}).nh_kh));if($body$$.introduce_code){let $contrIntroducer$$=global.controllers.INTRODUCER;await new Promise(($rs$$,$rj$$)=>{Controler.create($user$$,$contrIntroducer$$,{introduce_code:$body$$.introduce_code},($e$$,$intr$$)=>{if($e$$)return $rj$$($e$$.message||$e$$.error||$e$$);
|
|
9
9
|
$cust$$&&($cust$$.phu_trach=$intr$$.be_introduced_by);$rs$$()})})}$cust$$&&await Customer.asyncCreateCustomer($cust$$)}}
|
|
@@ -41,24 +41,24 @@ if($req$$.query.id_app&&($err$jscomp$4_p$$=await global.getModel("participant").
|
|
|
41
41
|
$req$$.session;$session$jscomp$1_user$$[$req$$.t_session]=0;$session$jscomp$1_user$$[$req$$.d_session]=""}else global.clientRedis.set($req$$.t_session,0),global.clientRedis.set($req$$.d_session,"");log.create({id_app:"LOGIN",id_func:"LOGIN",action:"LOCALLOGIN"},$req$$.user.email,$req$$.header("user-agent"),$req$$);$session$jscomp$1_user$$=$req$$.user;if($req$$.query.id_app&&global.mongoose.Types.ObjectId.isValid($req$$.query.id_app)){const $id_app$$=$req$$.query.id_app;let $group_id$$=$req$$.query.group_id&&
|
|
42
42
|
global.mongoose.Types.ObjectId.isValid($req$$.query.group_id)?$req$$.query.group_id:void 0;const $app$$=await App.findById($id_app$$);var $active_group_query_group$$={id_app:$id_app$$,$or:[{is_customer_group:!0},{is_partner_group:!0},{is_agent_group:!0},{is_pttt_group:!0}]};$group_id$$?$active_group_query_group$$._id=$group_id$$:$active_group_query_group$$.default_group=!0;$active_group_query_group$$=await UserGroup.findOne($active_group_query_group$$).lean();if($app$$&&$active_group_query_group$$){$group_id$$=
|
|
43
43
|
$active_group_query_group$$._id.toString();$active_group_query_group$$=$active_group_query_group$$.not_need_active;try{var $p$jscomp$3_session_created$$=await Participant.asyncCreateParticipant({id_app:$id_app$$,email:$session$jscomp$1_user$$.email,name:$session$jscomp$1_user$$.name,group_id:$group_id$$,active:$active_group_query_group$$});if($p$jscomp$3_session_created$$&&!$p$jscomp$3_session_created$$.active)return $res$$.status(401).send({message:"T\u00e0i kho\u1ea3n c\u1ee7a b\u1ea1n \u0111ang ch\u1edd \u0111\u01b0\u1ee3c x\u00e9t duy\u1ec7t",
|
|
44
|
-
active:!1});let $cust$$={ten_kh:$session$jscomp$1_user$$.name||$session$jscomp$1_user$$.email,email:$session$jscomp$1_user$$.email,id_app:$id_app$$,user_created:$session$jscomp$1_user$$.email,user_updated:$session$jscomp$1_user$$.email,kh_yn:!0,of_user:$session$jscomp$1_user$$.email};utils.isMobilePhone($session$jscomp$1_user$$.email,["vi-VN"])&&($cust$$.dien_thoai=$session$jscomp$1_user$$.email);try{await Customer.asyncCreateCustomer($cust$$)}catch($e$$){Logger.error("Auto create new customer with error:",
|
|
45
|
-
$e$$.message)}}catch($e$$){return Logger.error("can't add user",$session$jscomp$1_user$$.email,"to company",$app$$.name),$res$$.status(500).send($e$$)}}}const $accessToken$$=generateToken($session$jscomp$1_user$$);($p$jscomp$3_session_created$$=($req$$.cookies||{}).uid)&&User.updateOne({email:$session$jscomp$1_user$$.email,session_created:null},{session_created:$p$jscomp$3_session_created$$});(new Token({email:$session$jscomp$1_user$$.email,
|
|
46
|
-
only_id_app:$session$jscomp$1_user$$.token_id_app,token:$accessToken$$,agent:$agent$$,ip:"",once:$req$$.query.once==1||$req$$.query.once=="true"||$req$$.query.once==="1"?!0:!1})).save(function($e$$,$rs$$){if($e$$)return $res$$.status(500).send($e$$);$res$$.send({token:$accessToken$$,once:$rs$$.once})})});$app$$.get("/check-user/:email",$rateLimiter$$,function($req$$,$res$$){const $email$$=$req$$.params.email;
|
|
47
|
-
$res$$.send($user$$)}).catch($e$$=>{$res$$.status(400).send($e$$)})});$app$$.post("/signup",$rateLimiter$$,async($req$$,$res$$)=>{let $body$$=$req$$.body;$body$$.json&&($body$$=JSON.parse($body$$.json));if(!$body$$)return $res$$.status(400).send({error:"Kh\u00f4ng c\u00f3 n\u1ed9i dung"});
|
|
48
|
-
$req$$.query["g-recaptcha-response"];if(!$app$$)return $res$$.status(400).send("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u m\u1ed9t google recaptcha token");try{await permission.verifyReCaptcha($app$$)}catch($e$$){return $res$$.status(400).send($e$$.message||$e$$.error
|
|
49
|
-
if($app$$.options&&$app$$.options.one_account_per_device&&await Participant.findOne({session_created:$session_created$$,id_app:$body$$.id_app}).lean())return $res$$.status(400).send({error:"M\u1ed7i thi\u1ebft b\u1ecb ch\u1ec9 \u0111\u01b0\u1ee3c t\u1ea1o m\u1ed9t t\u00e0i kho\u1ea3n"})}if(!$body$$.email)return $res$$.status(400).send({error:"B\u1ea1n ch\u01b0a nh\u1eadp t\u00e0i kho\u1ea3n"})
|
|
50
|
-
["vi-VN"]))return $res$$.status(400).send({error:"T\u00e0i kho\u1ea3n \u0111\u0103ng nh\u1eadp ph\u1ea3i l\u00e0 1 \u0111\u1ecba ch\u1ec9 email ho\u1eb7c 1 s\u1ed1 \u0111i\u1ec7n tho\u1ea1i di \u0111\u1ed9ng"});if(!$body$$.name)return $res$$.status(400).send({error:"H\u1ecd v\u00e0 t\u00ean ch\u01b0a nh\u1eadp"});if($body$$.introduce_code&&$body$$.id_app&&!await global.getModel("introducecode").findOne({id_app:$body$$.id_app,
|
|
51
|
-
User.findOne({$or:[{email:$body$$.email},{"local.phone":$body$$.email}]},async function($error$$,$result$$){if($error$$)return $res$$.status(400).send($error$$);if($result$$)if(!$result$$.local||configs.require_verify&&!$result$$.local.active||$result$$.local.email!=$body$$.email)$result$$.local||($result$$.local={});else if($body$$.id_app)try{if(await global.getModel("participant").findOne({id_app:$body$$.id_app,
|
|
52
|
-
await addUserToApp($result$$,$body$$,$session_created$$);return $res$$.send("T\u00e0i kho\u1ea3n "+$body$$.email+" \u0111\u00e3 \u0111\u01b0\u1ee3c \u0111\u0103ng k\u00fd th\u00e0nh c\u00f4ng")}catch($e$$){return await global.getModel("participant").deleteOne({id_app:$body$$.id_app,email:$body$$.email}),$res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$})}else return $res$$.status(400).send({error:"T\u00e0i kho\u1ea3n "
|
|
53
|
-
else $result$$=new User,$result$$.email=$body$$.email,$result$$.local={};$result$$.local.email=$body$$.email;$result$$.local.name=$body$$.name;$result$$.local.active=!configs.require_verify;$result$$.partner=$body$$.partner;$result$$.session_created=$session_created$$;$body$$.email2&&validator.isEmail($body$$.email2)&&($result$$.email2=$body$$.email2);$result$$.name=$result$$.local.name;$body$$.picture?$result$$.local.picture
|
|
54
|
-
let $password$$;if($body$$.password){if($body$$.rePassword!==$body$$.password)return $res$$.status(400).send({error:"M\u1eadt kh\u1ea9u x\u00e1c nh\u1eadn kh\u00f4ng ch\u00ednh x\u00e1c"});if(!User.teststrengthPassword($body$$.password))return $res$$.status(400).send({error:"M\u1eadt kh\u1ea9u ph\u1ea3i c\u00f3 \u00edt nh\u1ea5t 6 k\u00fd t\u1ef1 v\u00e0 bao g\u1ed3m \u00edt nh\u1ea5t m\u1ed9t ch\u1eef s\u1ed1, m\u1ed9t ch\u1eef hoa v\u00e0 m\u1ed9t ch\u1eef th\u01b0\u1eddng"})
|
|
55
|
-
_crypto.createHash("md5").update($result$$.email+(new Date).toISOString()).digest("hex");$result$$.local.password=$result$$.generateHash($result$$.email+$password$$);$result$$.save(async function($app$jscomp$5_error$$,$newUser$$){if($app$jscomp$5_error$$)return $res$$.status(400).send({error:"Kh\u00f4ng th\u1ec3 \u0111\u0103ng k\u00fd"});log.create({id_app:"SIGNUP",id_func:"SIGNUP",action:"SIGNUP"},$result$$.email,$req$$.header("user-agent"),$req$$);if($body$$.cty_name){$app$jscomp$5_error$$=
|
|
56
|
-
|
|
57
|
-
3);$app$jscomp$5_error$$.expire_date=new Date($d$jscomp$1_now$$);$app$jscomp$5_error$$.save(function($error$$,$obj$$){if($error$$)return Logger.
|
|
58
|
-
$res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$})}let $accessToken$$;if($newUser$$.local.active)try{$accessToken$$=generateToken($newUser$$),await (new Token({email:$newUser$$.email,session_created:($req$$.cookies||{}).uid,token:$accessToken$$,agent:$req$$.headers["user-agent"],ip:"",once:$req$$.query.once==1||$req$$.query.once==
|
|
59
|
-
|
|
60
|
-
token:$accessToken$$,active:$newUser$$.local.active})):$res$$.send({msg:"T\u00e0i kho\u1ea3n "+$body$$.email+" \u0111\u00e3 \u0111\u01b0\u1ee3c t\u1ea1o",token:$accessToken$$,active:$newUser$$.local.active})})})});$app$$.get("/resetpassword"
|
|
61
|
-
if(!$address$$)return $res$$.status(400).send("Y\u00eau c\u1ea7u m\u1ed9t \u0111\u1ecba ch\u1ec9 email ho\u1eb7c s\u1ed1 \u0111i\u1ec7n tho\u1ea1i");$address$$=$address$$.toLowerCase();User.findOne({$or:[{"local.email":$address$$},{email:$address$$},
|
|
62
|
-
_crypto.createHash("md5").update((new Date).toISOString()).digest("hex");$result$$.local.rspassword=$result$$.generateHash($result$$.email+$newpassword$$);$result$$.save(function($error$$){if($error$$)return $res$$.status(400).send($error$$);loadTemplate("reset mat khau.html",
|
|
63
|
-
|
|
64
|
-
$error$$):Logger.info("send new password to",$result$$.email)});log.create({id_app:"RESETPASSWORD",id_func:"RESETPASSWORD",action:"RESETPASSWORD"},$result$$.email,$req$$.header("user-agent"),$req$$);$res$$.send("M\u1eadt kh\u1ea9u c\u1ee7a b\u1ea1n \u0111\u00e3 \u0111\u01b0\u1ee3c \u0111\u1ed5i th\u00e0nh c\u00f4ng. Ki\u1ec3m tra email \u0111\u1ec3 l\u1ea5y m\u1eadt kh\u1ea9u m\u1edbi, sau \u0111\u00f3 b\u1ea1n n\u00ean \u0111\u1ed5i m\u1eadt kh\u1ea9u n\u00e0y")})})})})};
|
|
44
|
+
active:!1});let $cust$$={ten_kh:$session$jscomp$1_user$$.name||$session$jscomp$1_user$$.email,email:$session$jscomp$1_user$$.email,id_app:$id_app$$,user_created:$session$jscomp$1_user$$.email,user_updated:$session$jscomp$1_user$$.email,kh_yn:!0,of_user:$session$jscomp$1_user$$.email};utils.isMobilePhone($session$jscomp$1_user$$.email,["vi-VN"])&&($cust$$.dien_thoai=$session$jscomp$1_user$$.email);try{await Customer.asyncCreateCustomer($cust$$)}catch($e$$){Logger.error("[auth][local] Auto create new customer with error:",
|
|
45
|
+
$e$$.message)}}catch($e$$){return Logger.error("[auth][local] can't add user",$session$jscomp$1_user$$.email,"to company",$app$$.name,$e$$.message||$e$$.error||$e$$),$res$$.status(500).send($e$$)}}}const $accessToken$$=generateToken($session$jscomp$1_user$$);($p$jscomp$3_session_created$$=($req$$.cookies||{}).uid)&&User.updateOne({email:$session$jscomp$1_user$$.email,session_created:null},{session_created:$p$jscomp$3_session_created$$}).catch(Logger.error);(new Token({email:$session$jscomp$1_user$$.email,
|
|
46
|
+
session_created:$p$jscomp$3_session_created$$,id_apps:$session$jscomp$1_user$$.token_id_apps,only_id_app:$session$jscomp$1_user$$.token_id_app,token:$accessToken$$,agent:$agent$$,ip:"",once:$req$$.query.once==1||$req$$.query.once=="true"||$req$$.query.once==="1"?!0:!1})).save(function($e$$,$rs$$){if($e$$)return $res$$.status(500).send($e$$);$res$$.send({token:$accessToken$$,once:$rs$$.once})})});$app$$.get("/check-user/:email",$rateLimiter$$,function($req$$,$res$$){const $email$$=$req$$.params.email;
|
|
47
|
+
User.findOne({$or:[{email:$email$$},{"local.phone":$email$$}]},{email:1,name:1,picture:1}).lean().then(function($user$$){if(!$user$$)return $res$$.status(400).send(`T\u00e0i kho\u1ea3n ${$email$$} kh\u00f4ng t\u1ed3n t\u1ea1i`);$res$$.send($user$$)}).catch($e$$=>{$res$$.status(400).send($e$$)})});$app$$.post("/signup",$rateLimiter$$,async($req$$,$res$$)=>{let $body$$=$req$$.body;$body$$.json&&($body$$=JSON.parse($body$$.json));if(!$body$$)return $res$$.status(400).send({error:"Kh\u00f4ng c\u00f3 n\u1ed9i dung"});
|
|
48
|
+
if($body$$.id_app&&!global.mongoose.Types.ObjectId.isValid($body$$.id_app))return $res$$.status(400).send("id_app kh\u00f4ng h\u1ee3p l\u1ec7");if(configs.GOOGLE_RECAPTCHA_SECRET_KEY){var $app$$=$body$$["g-recaptcha-response"]||$req$$.query["g-recaptcha-response"];if(!$app$$)return $res$$.status(400).send("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u m\u1ed9t google recaptcha token");try{await permission.verifyReCaptcha($app$$)}catch($e$$){return $res$$.status(400).send($e$$.message||$e$$.error||
|
|
49
|
+
$e$$)}}let $session_created$$=($req$$.cookies||{}).uid;if($session_created$$&&$body$$.id_app){$app$$=await App.findById($body$$.id_app);if(!$app$$)return $res$$.status(400).send({error:"C\u00f4ng ty kh\u00f4ng t\u1ed3n t\u1ea1i"});if($app$$.options&&$app$$.options.one_account_per_device&&await Participant.findOne({session_created:$session_created$$,id_app:$body$$.id_app}).lean())return $res$$.status(400).send({error:"M\u1ed7i thi\u1ebft b\u1ecb ch\u1ec9 \u0111\u01b0\u1ee3c t\u1ea1o m\u1ed9t t\u00e0i kho\u1ea3n"})}if(!$body$$.email)return $res$$.status(400).send({error:"B\u1ea1n ch\u01b0a nh\u1eadp t\u00e0i kho\u1ea3n"});
|
|
50
|
+
$body$$.email=$body$$.email.trim().toLowerCase();if(!validator.isEmail($body$$.email)&&!utils.isMobilePhone($body$$.email,["vi-VN"]))return $res$$.status(400).send({error:"T\u00e0i kho\u1ea3n \u0111\u0103ng nh\u1eadp ph\u1ea3i l\u00e0 1 \u0111\u1ecba ch\u1ec9 email ho\u1eb7c 1 s\u1ed1 \u0111i\u1ec7n tho\u1ea1i di \u0111\u1ed9ng"});if(!$body$$.name)return $res$$.status(400).send({error:"H\u1ecd v\u00e0 t\u00ean ch\u01b0a nh\u1eadp"});if($body$$.introduce_code&&$body$$.id_app&&!await global.getModel("introducecode").findOne({id_app:$body$$.id_app,
|
|
51
|
+
status:!0,introduce_code:$body$$.introduce_code}).lean())return $res$$.status(400).send({error:"M\u00e3 gi\u1edbi thi\u1ec7u kh\u00f4ng h\u1ee3p l\u1ec7"});User.findOne({$or:[{email:$body$$.email},{"local.phone":$body$$.email}]},async function($error$$,$result$$){if($error$$)return $res$$.status(400).send($error$$);if($result$$)if(!$result$$.local||configs.require_verify&&!$result$$.local.active||$result$$.local.email!=$body$$.email)$result$$.local||($result$$.local={});else if($body$$.id_app)try{if(await global.getModel("participant").findOne({id_app:$body$$.id_app,
|
|
52
|
+
email:$body$$.email}))return $res$$.status(400).send({error:"T\u00e0i kho\u1ea3n n\u00e0y \u0111\u00e3 t\u1ed3n t\u1ea1i"});await addUserToApp($result$$,$body$$,$session_created$$);return $res$$.send("T\u00e0i kho\u1ea3n "+$body$$.email+" \u0111\u00e3 \u0111\u01b0\u1ee3c \u0111\u0103ng k\u00fd th\u00e0nh c\u00f4ng")}catch($e$$){return await global.getModel("participant").deleteOne({id_app:$body$$.id_app,email:$body$$.email}),$res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$})}else return $res$$.status(400).send({error:"T\u00e0i kho\u1ea3n "+
|
|
53
|
+
$body$$.email+" \u0111\u00e3 \u0111\u01b0\u1ee3c \u0111\u0103ng k\u00fd"});else $result$$=new User,$result$$.email=$body$$.email,$result$$.local={};$result$$.local.email=$body$$.email;$result$$.local.name=$body$$.name;$result$$.local.active=!configs.require_verify;$result$$.partner=$body$$.partner;$result$$.session_created=$session_created$$;$body$$.email2&&validator.isEmail($body$$.email2)&&($result$$.email2=$body$$.email2);$result$$.name=$result$$.local.name;$body$$.picture?$result$$.local.picture=
|
|
54
|
+
$body$$.picture:$result$$.local.picture||($result$$.local.picture="/images/avatar.jpg");let $password$$;if($body$$.password){if($body$$.rePassword!==$body$$.password)return $res$$.status(400).send({error:"M\u1eadt kh\u1ea9u x\u00e1c nh\u1eadn kh\u00f4ng ch\u00ednh x\u00e1c"});if(!User.teststrengthPassword($body$$.password))return $res$$.status(400).send({error:"M\u1eadt kh\u1ea9u ph\u1ea3i c\u00f3 \u00edt nh\u1ea5t 6 k\u00fd t\u1ef1 v\u00e0 bao g\u1ed3m \u00edt nh\u1ea5t m\u1ed9t ch\u1eef s\u1ed1, m\u1ed9t ch\u1eef hoa v\u00e0 m\u1ed9t ch\u1eef th\u01b0\u1eddng"});
|
|
55
|
+
$password$$=$body$$.password}else $password$$=_crypto.createHash("md5").update($result$$.email+(new Date).toISOString()).digest("hex");$result$$.local.password=$result$$.generateHash($result$$.email+$password$$);$result$$.save(async function($app$jscomp$5_error$$,$newUser$$){if($app$jscomp$5_error$$)return $res$$.status(400).send({error:"Kh\u00f4ng th\u1ec3 \u0111\u0103ng k\u00fd"});log.create({id_app:"SIGNUP",id_func:"SIGNUP",action:"SIGNUP"},$result$$.email,$req$$.header("user-agent"),$req$$);if($body$$.cty_name){$app$jscomp$5_error$$=
|
|
56
|
+
new App;$app$jscomp$5_error$$.user_created=$result$$.email;$app$jscomp$5_error$$.user_updated=$result$$.email;$app$jscomp$5_error$$.name=$body$$.cty_name;var $d$jscomp$1_now$$=new Date;$app$jscomp$5_error$$.ngay_dn=new Date($d$jscomp$1_now$$.getFullYear(),0,1);$app$jscomp$5_error$$.ngay_ks=new Date($d$jscomp$1_now$$.getFullYear()-1,12,0);$app$jscomp$5_error$$.nam_bd=$d$jscomp$1_now$$.getFullYear();$app$jscomp$5_error$$.ngay_ky1=new Date($d$jscomp$1_now$$.getFullYear(),0,1);$d$jscomp$1_now$$=new Date;
|
|
57
|
+
$d$jscomp$1_now$$.setMonth($d$jscomp$1_now$$.getMonth()+3);$app$jscomp$5_error$$.expire_date=new Date($d$jscomp$1_now$$);$app$jscomp$5_error$$.save(function($error$$,$obj$$){if($error$$)return Logger.error("[signup] Khong tao duoc new app: "+$error$$);require("../libs/initDatabase").init($obj$$._id,function($error$$){$error$$&&Logger.error("[signup] Can't init database \n"+$error$$)})})}try{await addUserToApp($newUser$$,$body$$,$session_created$$)}catch($e$$){return Logger.error("[signup] add user to app",
|
|
58
|
+
$e$$.message||$e$$.error||$e$$),await global.getModel("participant").deleteOne({id_app:$body$$.id_app,email:$body$$.email}),await User.deleteOne({email:$body$$.email}),$res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$})}let $accessToken$$;if($newUser$$.local.active)try{$accessToken$$=generateToken($newUser$$),await (new Token({email:$newUser$$.email,session_created:($req$$.cookies||{}).uid,token:$accessToken$$,agent:$req$$.headers["user-agent"],ip:"",once:$req$$.query.once==1||$req$$.query.once==
|
|
59
|
+
"true"||$req$$.query.once==="1"?!0:!1})).save()}catch($e$$){Logger.error("[signup] can't gen new token for new user:"+$newUser$$.email,$e$$)}validator.isEmail($body$$.email)&&!$body$$.password?(loadTemplate("thong tin dang nhap.html",{email:$result$$.email,password:$password$$,receiver_name:$body$$.name},function($error$$,$html$$){if($error$$)return Logger.info($error$$);email.sendHtml({to:{name:$result$$.name,address:$result$$.email},subject:"Th\u00f4ng tin t\u00e0i kho\u1ea3n",html:$html$$},function($error$$){$error$$&&
|
|
60
|
+
Logger.error("Khong the gui email thon tin tai khoan cho nguoi dung\n"+$error$$)})}),$res$$.send({msg:"T\u00e0i kho\u1ea3n c\u1ee7a b\u1ea1n \u0111\u00e3 \u0111\u01b0\u1ee3c t\u1ea1o. Ki\u1ec3m tra email \u0111\u1ec3 l\u1ea5y th\u00f4ng tin \u0111\u0103ng nh\u1eadp",token:$accessToken$$,active:$newUser$$.local.active})):$res$$.send({msg:"T\u00e0i kho\u1ea3n "+$body$$.email+" \u0111\u00e3 \u0111\u01b0\u1ee3c t\u1ea1o",token:$accessToken$$,active:$newUser$$.local.active})})})});$app$$.get("/resetpassword",
|
|
61
|
+
$rateLimiter$$,async($req$$,$res$$)=>{if(configs.GOOGLE_RECAPTCHA_SECRET_KEY)try{await permission.verifyReCaptcha($req$$.query["g-recaptcha-response"])}catch($e$$){return $res$$.status(400).send($e$$.message||$e$$.error||$e$$)}let $address$$=$req$$.query.email;if(!$address$$)return $res$$.status(400).send("Y\u00eau c\u1ea7u m\u1ed9t \u0111\u1ecba ch\u1ec9 email ho\u1eb7c s\u1ed1 \u0111i\u1ec7n tho\u1ea1i");$address$$=$address$$.toLowerCase();User.findOne({$or:[{"local.email":$address$$},{email:$address$$},
|
|
62
|
+
{email2:$address$$}]},function($error$$,$result$$){if($error$$)return $res$$.status(400).send($error$$);if(!$result$$)return $res$$.status(400).send(`T\u00e0i kho\u1ea3n ${$address$$} ch\u01b0a \u0111\u01b0\u1ee3c \u0111\u0103ng k\u00fd`);let $newpassword$$=_crypto.createHash("md5").update((new Date).toISOString()).digest("hex");$result$$.local.rspassword=$result$$.generateHash($result$$.email+$newpassword$$);$result$$.save(function($error$$){if($error$$)return $res$$.status(400).send($error$$);loadTemplate("reset mat khau.html",
|
|
63
|
+
{receiver_name:$result$$.name,email:$result$$.email,password:$newpassword$$},function($error$$,$html$$){if($error$$)return $res$$.status(400).send($error$$);$result$$.email&&validator.isEmail($result$$.email)&&email.sendHtml({to:{name:$result$$.name,address:$result$$.email},subject:"\u0110\u1ed5i m\u1eadt kh\u1ea9u",html:$html$$},function($error$$){$error$$?Logger.error("Khong the gui thong tin tai khoan cho nguoi su dung\n"+$error$$):Logger.info("send new password to",$result$$.email)});$result$$.email2&&
|
|
64
|
+
validator.isEmail($result$$.email2)&&email.sendHtml({to:{name:$result$$.name,address:$result$$.email2},subject:"\u0110\u1ed5i m\u1eadt kh\u1ea9u",html:$html$$},function($error$$){$error$$?Logger.error("Khong the gui thong tin tai khoan cho nguoi su dung\n"+$error$$):Logger.info("send new password to",$result$$.email)});log.create({id_app:"RESETPASSWORD",id_func:"RESETPASSWORD",action:"RESETPASSWORD"},$result$$.email,$req$$.header("user-agent"),$req$$);$res$$.send("M\u1eadt kh\u1ea9u c\u1ee7a b\u1ea1n \u0111\u00e3 \u0111\u01b0\u1ee3c \u0111\u1ed5i th\u00e0nh c\u00f4ng. Ki\u1ec3m tra email \u0111\u1ec3 l\u1ea5y m\u1eadt kh\u1ea9u m\u1edbi, sau \u0111\u00f3 b\u1ea1n n\u00ean \u0111\u1ed5i m\u1eadt kh\u1ea9u n\u00e0y")})})})})};
|
|
@@ -10,7 +10,7 @@ fields:["tg_tk","kg_kiem_tra_ton_kho","kg_kiem_tra_ton_kho_tt",{cb:"combo"},"ten
|
|
|
10
10
|
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$$,
|
|
11
11
|
($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"),
|
|
12
12
|
$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$$($e$$)})})():$callback$$()}},$e$$=>
|
|
13
|
-
{$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,
|
|
13
|
+
{$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,action_code:"view"}){const $self$$=
|
|
14
14
|
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"]||$req$$.connection.remoteAddress;
|
|
15
15
|
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||
|
|
16
16
|
$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$$):
|
|
@@ -28,8 +28,8 @@ $e$jscomp$7_result$$;$data$jscomp$5_data$jscomp$6_data$jscomp$7_returnvalue$$?.t
|
|
|
28
28
|
"application/xml");$res$$.setHeader("Content-Disposition",'attachment; filename="'+$rptId$$+'".xml');$data$jscomp$5_data$jscomp$6_data$jscomp$7_returnvalue$$=$e$jscomp$7_result$$;$data$jscomp$5_data$jscomp$6_data$jscomp$7_returnvalue$$?.type==="Buffer"&&Array.isArray($data$jscomp$5_data$jscomp$6_data$jscomp$7_returnvalue$$.data)&&($data$jscomp$5_data$jscomp$6_data$jscomp$7_returnvalue$$=Buffer.from($data$jscomp$5_data$jscomp$6_data$jscomp$7_returnvalue$$.data));$res$$.setHeader("Content-Length",$data$jscomp$5_data$jscomp$6_data$jscomp$7_returnvalue$$.length);
|
|
29
29
|
$res$$.end($data$jscomp$5_data$jscomp$6_data$jscomp$7_returnvalue$$);break;default:$res$$.send($e$jscomp$7_result$$)}})}catch($e$$){$res$$.status(400).send($e$$)}};$router$$.route(`${this.base_path+this.module}`).get($mainRoute$$);$router$$.route(`${this.base_path+this.module}`).post($mainRoute$$);$router$$.route(`${this.base_path+this.module}/excel`).get($excelRoute$$);$router$$.route(`${this.base_path+this.module}/excel`).post($excelRoute$$);$router$$.route(`${this.base_path+this.module}/export`).get($excelRoute$$);
|
|
30
30
|
$router$$.route(`${this.base_path+this.module}/export`).post($excelRoute$$)}getData($req$$,$callback$$){const $ctrl$$=this;let $callback_run$$=!1;setImmediate(()=>{try{$ctrl$$.fecthDataFunc($req$$,($err$$,$data$$,$event$$)=>{if($ctrl$$.options?.stream){if($err$$)return $callback$$($err$$);$event$$!="data"||$callback_run$$||($callback_run$$=!0,this.handleResult($req$$,{error:$err$$,result:$data$$},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)}))}else $callback_run$$=!0,this.handleResult($req$$,{error:$err$$,
|
|
31
|
-
result:$data$$},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})})}catch($e$$){Logger.error("[report controller] [getData]",$e$$),$callback$$($e$$.message)}})}createRoute($routeName$$,$callbackRoute_handler$$,$_options$$={method:"GET",not_use_worker:!1,
|
|
31
|
+
result:$data$$},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})})}catch($e$$){Logger.error("[report controller] [getData]",$e$$),$callback$$($e$$.message)}})}createRoute($routeName$$,$callbackRoute_handler$$,$_options$$={method:"GET",not_use_worker:!1,action_code:"view"}){const $self$$=this;$_options$$.method=$_options$$.method?$_options$$.method.toUpperCase():"GET";const $route_action_key$$=`rpt_route_action_${$self$$.module}_${$routeName$$}_${$_options$$.method}`;$self$$[$route_action_key$$]=$callbackRoute_handler$$;
|
|
32
32
|
$callbackRoute_handler$$=async function($ip$jscomp$2_req$$,$res$$){const {query:$query$$,body:$body$$,user:$user$$,params:$params$$,files:$files$$}=$ip$jscomp$2_req$$;var $_req$jscomp$2_user_agent$$=$ip$jscomp$2_req$$.header("user-agent");$ip$jscomp$2_req$$=$ip$jscomp$2_req$$.ip||$ip$jscomp$2_req$$.headers["x-forwarded-for"]||$ip$jscomp$2_req$$.connection.remoteAddress;try{if($_req$jscomp$2_user_agent$$={handler:"rptCreateRouteHandler",routeName:$routeName$$,_options:$_options$$,route_action_key:$route_action_key$$,
|
|
33
|
-
query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$_req$jscomp$2_user_agent$$,ip:$ip$jscomp$2_req$$,files:$files$$},!global.reportMainPool||global.reportMainPool.fullQueue()||$_options$$.not_use_worker)handlers.rptCreateRouteHandler(
|
|
33
|
+
query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$_req$jscomp$2_user_agent$$,ip:$ip$jscomp$2_req$$,files:$files$$},!global.reportMainPool||global.reportMainPool.fullQueue()||$_options$$.not_use_worker)handlers.rptCreateRouteHandler($self$$,$_req$jscomp$2_user_agent$$,($e$$,$returnvalue$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($returnvalue$$)});else{const $id_task$$=`report-create-route-${crypto.randomBytes(20).toString("hex")}`;global.reportMainPool.exec({id_task:$id_task$$,
|
|
34
34
|
req:$_req$jscomp$2_user_agent$$,module:$self$$.module.toUpperCase(),configs:JSON.stringify(configs)},$response$jscomp$6_result$$=>{if($response$jscomp$6_result$$.error)return $res$$.status(400).send($response$jscomp$6_result$$.error);({result:$response$jscomp$6_result$$}=$response$jscomp$6_result$$);$res$$.send($response$jscomp$6_result$$)})}}catch($e$$){$res$$.status(400).send($e$$)}};$_options$$.method=="DELETE"?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).delete($callbackRoute_handler$$):
|
|
35
35
|
$_options$$.method=="POST"?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).post($callbackRoute_handler$$):$_options$$.method=="PUT"?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).put($callbackRoute_handler$$):this.router.route(`${this.base_path+this.module}/${$routeName$$}`).get($callbackRoute_handler$$)}}module.exports=controllerRPT;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
const async=require("async"),Moment=require("moment-timezone"),moment=$time$$=>Moment.tz($time$$,configs.timezone||"Asia/Ho_Chi_Minh"),numeral=require("numeral"),_=require("lodash"),validate=require("../libs/validate"),permission=require("../libs/permission"),{onAfterCommit,executeInTransaction}=require("../libs/sessionContext.js"),{evalute,convertObjectIdsToStrings}=require("../libs/utils"),{asyncBodyToJson,ERRORS,getNextSequence,isExists,createIdRef,fields_sync_master_detail,postData,runWebhooks}=
|
|
2
|
-
require("./controllerUtils"),createHandler=async($ctrl$$,$req$$,$callback$$)=>{let {user:$user$$,data:$data$$,id_be_supply_by_user:$id_be_supply_by_user$$,action:$action$$}=$req$$;$action$$||="add";let $listinfo_code$$=$req$$?.body?.["listinfo-code"]||$req$$?.headers?.["listinfo-code"]||$req$$?.headers?.["Listinfo-Code"]||$req$$.query["listinfo-code"]||$data
|
|
3
|
-
$data$$.listinfo_code=$listinfo_code$$;try{const $model$$=$ctrl$$.model;let $voucher_options$$=(await global.getModel("options").findOne({id_app:$user$$.current_id_app,id_func:$listinfo_code$$.toLowerCase()}).lean()||{}).option;$voucher_options$$||$ctrl$$.name===$listinfo_code$$||($voucher_options$$=(await global.getModel("options").findOne({id_app:$user$$.current_id_app,id_func:$ctrl$$.name}).lean()||
|
|
4
|
-
$ctrl$$,$user$$.current_id_app,$voucher_options$$)}catch($e$$){return $callback$$($e$$.message||$e$$.error||$e$$)}$schema_paths$$.ma_ct&&$ctrl$$.options.isVoucher&&($v_data$$.ma_ct=$ctrl$$.name.toUpperCase());delete $v_data$$.session_created;delete $v_data$$.session_updated;$req$$&&$schema_paths$$.session_created&&($v_data$$.session_created=($req$$.cookies||{}).uid);if($ctrl$$.options.requireRecaptchaToken&&
|
|
5
|
-
try{await permission.verifyReCaptcha($v_data$$["g-recaptcha-response"])}catch($e$$){return $callback$$($e$$.message||$e$$.error||$e$$)}}let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($v_data$$,{action:$action$$,user:$user$$}));if($requireOtp$$&&$action$$!="import")try{await permission.verifyOTP($user$$.email
|
|
6
|
-
await new Promise(($resolve$$,$reject$$)=>{try{$ctrl$$.dynamicCreating($user$$,$v_data$$,function($error$$,$v_data$$){if($error$$)return $reject$$($error$$);$resolve$$($v_data$$)},{listinfo_code:$listinfo_code$$,req:$req$$})}catch($e$$){return $reject$$($e$$)}})}catch($e$$){return $callback$$($e$$.message||$e$$.error
|
|
7
|
-
$f$$!=="exfields"||$obj$$.exfields||($obj$$.exfields={}));$schema_paths$$.id_app&&($obj$$.id_app=$user$$.current_id_app);const $checkVoucherNumber$$=$callback$$=>{$model$$.schema.paths.ngay_ct&&$obj$$.ngay_ct?setImmediate(()=>{if($voucher_options$$&&($voucher_options$$?.trang_thai_create_voucher_numbers?.length==0||$voucher_options$$?.trang_thai_create_voucher_numbers?.indexOf($obj$$.trang_thai)>=
|
|
8
|
-
so_ct:$obj$$.so_ct,listinfo_code:$listinfo_code$$},$tu_ngay$$,$den_ngay$$;switch($voucher_options$$.check_so_ct){case "1":$tu_ngay$$=moment($obj$$.ngay_ct).startOf("day").toDate();$den_ngay$$=moment($obj$$.ngay_ct).endOf("day").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "2":$tu_ngay$$=moment($obj$$.ngay_ct).startOf("month").toDate();$den_ngay$$=moment($obj$$.ngay_ct).endOf("month").toDate()
|
|
9
|
-
moment($obj$$.ngay_ct).startOf("quarter").toDate();$den_ngay$$=moment($obj$$.ngay_ct).endOf("quarter").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "8":$tu_ngay$$=moment($obj$$.ngay_ct).startOf("year").toDate(),$den_ngay$$=moment($obj$$.ngay_ct).endOf("year").toDate(),$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().then($rs$$=>
|
|
10
|
-
" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c";if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)});else $callback$$($msgError$$)}else $callback$$()})}).catch($e$$=>{Logger.error($e$$)})}else $callback$$()}):$callback$$()},$File$$=global.getModel("file")
|
|
11
|
-
await $ctrl$$.notNeedRight($user$$,{action:$action$$,obj:$obj$$});permission.hasRight($obj$$.id_app,$user$$.email,$ctrl$$.module,$action$$,function($error$$,$hr$$,$c_app$$){setImmediate(()=>{if($error$$||!$hr$$)return $error$$=$error$$||"",$callback$$({error:$error$$.error||$error$$||ERRORS.ERR_NOT_PERMIT,code:$error$$.code||ERRORS.ERR_NOT_PERMIT_CODE});$ctrl$$.checkData($c_app
|
|
12
|
-
for(let $f$$ of Object.keys($schema_paths$$))$error$$=$_obj$$.get?$_obj$$.get($f$$):$_obj$$[$f$$],$obj$$.set($f$$,$error$$);$callback$$(null,$obj$$)},{data:$data$$,action:$action$$}):$callback$$(null,$obj$$)})})},{data:$obj$$,notNeedRight:$notNeedRight$$,listinfo_code:$listinfo_code$$})})},($obj$$,$callback$$)=>{setImmediate(()=>{let $ma_ct
|
|
13
|
-
$obj$$.toObject?convertObjectIdsToStrings($obj$$.toObject()):{...$obj$$};let $keys_options$$=Object.keys($_options_qct$$);global.getModel("dmqct").find($condition_qct$$).lean().then($rs$$=>{setImmediate(()=>{let $qcts$$=($rs$$||[]).filter($qct$$=>$qct$$.field!=="so_ct"&&!$obj$$[$qct$$.field]&&$model$$.schema.paths[$qct$$.field]);$qcts$$=$qcts$$.filter($qct$$=>
|
|
14
|
-
return $str_func$$.indexOf("async ")>0?!1:evalute($str_func$$,{...$_options_qct$$,master:{...$_options_qct$$},moment,numeral})}catch($e$$){return Logger.error("Error find quyen chung tu",$e$$.message,$qct$$.dieu_kien),!1}else return!0});async.mapSeries($qcts$$,($qct$$,$cb$$)=>{let $field$$=$qct$$.field,$_options$$={...$_options_qct$$};$_options$$.id_qct
|
|
15
|
-
$field$$,function($e$$,$rs$$){setImmediate(async()=>{if($e$$)return $callback$$($e$$);$obj$$[$field$$]=$rs$$[$field$$];$qct$$.check_duplicate?await $model$$.findOne({id_app:$obj$$.id_app,[$field$$]:$obj$$[$field$$]},{[$field$$]:1}).lean()?$count$$>=9?$callback$$(`Kh\u00f4ng th\u1ec3 t\u1ef1 \u0111\u1ed9ng t\u1ea1o gi\u00e1 tr\u1ecb cho field ${$field$$}. Gi\u00e1 tr\u1ecb "${$obj$$[$field$$]}" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ki\u1ec3m tra l\u1ea1i th\u00f4ng s\u1ed1 quy\u1ec3n ch\u1ee9ng t\u1eeb sao cho gi\u00e1 tr\u1ecb s\u1ebd t\u1ea1o ra kh\u00f4ng b\u1ecb tr\u00f9ng v\u1edbi gi\u00e1 tr\u1ecb \u0111\u00e3 c\u00f3`):
|
|
2
|
+
require("./controllerUtils"),createHandler=async($ctrl$$,$req$$,$callback$$)=>{$req$$.headers=$req$$.headers||{};$req$$.body=$req$$.body||{};$req$$.query=$req$$.query||{};$req$$.data=$req$$.data||{};let {user:$user$$,data:$data$$,id_be_supply_by_user:$id_be_supply_by_user$$,action:$action$$}=$req$$;$action$$||="add";let $listinfo_code$$=$req$$?.body?.["listinfo-code"]||$req$$?.headers?.["listinfo-code"]||$req$$?.headers?.["Listinfo-Code"]||$req$$.query?.["listinfo-code"]||$data$$?.listinfo_code;$listinfo_code$$=
|
|
3
|
+
$listinfo_code$$||$ctrl$$.name;$req$$.headers=$req$$.headers||{};$req$$.headers["Listinfo-Code"]=$listinfo_code$$;$data$$.listinfo_code=$listinfo_code$$;try{const $model$$=$ctrl$$.model;let $voucher_options$$=(await global.getModel("options").findOne({id_app:$user$$.current_id_app,id_func:$listinfo_code$$.toLowerCase()}).lean()||{}).option;$voucher_options$$||$ctrl$$.name===$listinfo_code$$||($voucher_options$$=(await global.getModel("options").findOne({id_app:$user$$.current_id_app,id_func:$ctrl$$.name}).lean()||
|
|
4
|
+
{}).option);const $schema_paths$$=$model$$.schema.paths;let $v_data$$;try{$v_data$$=await asyncBodyToJson($data$$,$ctrl$$,$user$$.current_id_app,$voucher_options$$)}catch($e$$){return $callback$$($e$$.message||$e$$.error||$e$$)}$schema_paths$$.ma_ct&&$ctrl$$.options.isVoucher&&($v_data$$.ma_ct=$ctrl$$.name.toUpperCase());delete $v_data$$.session_created;delete $v_data$$.session_updated;$req$$&&$schema_paths$$.session_created&&($v_data$$.session_created=($req$$.cookies||{}).uid);if($ctrl$$.options.requireRecaptchaToken&&
|
|
5
|
+
configs.GOOGLE_RECAPTCHA_SECRET_KEY){if(!$v_data$$["g-recaptcha-response"])return $callback$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u g-recaptcha-response");try{await permission.verifyReCaptcha($v_data$$["g-recaptcha-response"])}catch($e$$){return $callback$$($e$$.message||$e$$.error||$e$$)}}let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($v_data$$,{action:$action$$,user:$user$$}));if($requireOtp$$&&$action$$!="import")try{await permission.verifyOTP($user$$.email,
|
|
6
|
+
$v_data$$["otp-id"],$v_data$$["otp-code"])}catch($e$$){return $callback$$({error:$e$$.message||$e$$.error||$e$$,code:ERRORS.ERR_VERIFY_OTP})}if($ctrl$$.dynamicCreating)try{$v_data$$=await new Promise(($resolve$$,$reject$$)=>{try{$ctrl$$.dynamicCreating($user$$,$v_data$$,function($error$$,$v_data$$){if($error$$)return $reject$$($error$$);$resolve$$($v_data$$)},{listinfo_code:$listinfo_code$$,req:$req$$})}catch($e$$){return $reject$$($e$$)}})}catch($e$$){return $callback$$($e$$.message||$e$$.error||
|
|
7
|
+
$e$$)}const $obj$$=new $model$$;$schema_paths$$.exfields&&($obj$$.exfields=$v_data$$.exfields||{});for(let $f$$ in $v_data$$)$schema_paths$$[$f$$]&&($obj$$.set($f$$,$v_data$$[$f$$]),$f$$!=="exfields"||$obj$$.exfields||($obj$$.exfields={}));$schema_paths$$.id_app&&($obj$$.id_app=$user$$.current_id_app);const $checkVoucherNumber$$=$callback$$=>{$model$$.schema.paths.ngay_ct&&$obj$$.ngay_ct?setImmediate(()=>{if($voucher_options$$&&($voucher_options$$?.trang_thai_create_voucher_numbers?.length==0||$voucher_options$$?.trang_thai_create_voucher_numbers?.indexOf($obj$$.trang_thai)>=
|
|
8
|
+
0)&&$voucher_options$$.check_so_ct&&$voucher_options$$.check_so_ct!=="0"){let $query_check$$={id_app:$obj$$.id_app,so_ct:$obj$$.so_ct,listinfo_code:$listinfo_code$$},$tu_ngay$$,$den_ngay$$;switch($voucher_options$$.check_so_ct){case "1":$tu_ngay$$=moment($obj$$.ngay_ct).startOf("day").toDate();$den_ngay$$=moment($obj$$.ngay_ct).endOf("day").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "2":$tu_ngay$$=moment($obj$$.ngay_ct).startOf("month").toDate();$den_ngay$$=moment($obj$$.ngay_ct).endOf("month").toDate();
|
|
9
|
+
$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "3":$tu_ngay$$=moment($obj$$.ngay_ct).startOf("quarter").toDate();$den_ngay$$=moment($obj$$.ngay_ct).endOf("quarter").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "8":$tu_ngay$$=moment($obj$$.ngay_ct).startOf("year").toDate(),$den_ngay$$=moment($obj$$.ngay_ct).endOf("year").toDate(),$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().then($rs$$=>
|
|
10
|
+
{setImmediate(()=>{if($rs$$){let $msgError$$="S\u1ed1 ch\u1ee9ng t\u1eeb "+$obj$$.so_ct+" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c";if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)});else $callback$$($msgError$$)}else $callback$$()})}).catch($e$$=>{Logger.error($e$$)})}else $callback$$()}):$callback$$()},$File$$=global.getModel("file"),
|
|
11
|
+
$Support$$=global.getModel("support");async.waterfall([function($callback$$){setImmediate(async function(){let $notNeedRight$$=await $ctrl$$.notNeedRight($user$$,{action:$action$$,obj:$obj$$});permission.hasRight($obj$$.id_app,$user$$.email,$ctrl$$.module,$action$$,function($error$$,$hr$$,$c_app$$){setImmediate(()=>{if($error$$||!$hr$$)return $error$$=$error$$||"",$callback$$({error:$error$$.error||$error$$||ERRORS.ERR_NOT_PERMIT,code:$error$$.code||ERRORS.ERR_NOT_PERMIT_CODE});$ctrl$$.checkData($c_app$$,
|
|
12
|
+
$obj$$,$e$$=>{if($e$$)return $callback$$($e$$);$ctrl$$.creating?$ctrl$$.creating($user$$,$obj$$,function($error$$,$_obj$$){if($error$$)return $callback$$($error$$);for(let $f$$ of Object.keys($schema_paths$$))$error$$=$_obj$$.get?$_obj$$.get($f$$):$_obj$$[$f$$],$obj$$.set($f$$,$error$$);$callback$$(null,$obj$$)},{data:$data$$,action:$action$$}):$callback$$(null,$obj$$)})})},{data:$obj$$,notNeedRight:$notNeedRight$$,listinfo_code:$listinfo_code$$})})},($obj$$,$callback$$)=>{setImmediate(()=>{let $ma_ct$$=
|
|
13
|
+
$listinfo_code$$||$ctrl$$.name;const $condition_qct$$={status:!0,id_app:$obj$$.id_app,cac_ma_ct:$ma_ct$$.toLowerCase()};let $_options_qct$$;$_options_qct$$=$obj$$.toObject?convertObjectIdsToStrings($obj$$.toObject()):{...$obj$$};let $keys_options$$=Object.keys($_options_qct$$);global.getModel("dmqct").find($condition_qct$$).lean().then($rs$$=>{setImmediate(()=>{let $qcts$$=($rs$$||[]).filter($qct$$=>$qct$$.field!=="so_ct"&&!$obj$$[$qct$$.field]&&$model$$.schema.paths[$qct$$.field]);$qcts$$=$qcts$$.filter($qct$$=>
|
|
14
|
+
{if($qct$$.dieu_kien&&$keys_options$$.length>0)try{let $str_func$$=$qct$$.dieu_kien;$str_func$$.indexOf("return ")!==0&&($str_func$$=`return ${$str_func$$}`);return $str_func$$.indexOf("async ")>0?!1:evalute($str_func$$,{...$_options_qct$$,master:{...$_options_qct$$},moment,numeral})}catch($e$$){return Logger.error("Error find quyen chung tu",$e$$.message,$qct$$.dieu_kien),!1}else return!0});async.mapSeries($qcts$$,($qct$$,$cb$$)=>{let $field$$=$qct$$.field,$_options$$={...$_options_qct$$};$_options$$.id_qct=
|
|
15
|
+
$qct$$._id.toString();let $count$$=0;async.whilst(function($cb$$){$cb$$(null,$count$$<10)},function($callback$$){getNextSequence($obj$$.id_app,$ma_ct$$,$field$$,function($e$$,$rs$$){setImmediate(async()=>{if($e$$)return $callback$$($e$$);$obj$$[$field$$]=$rs$$[$field$$];$qct$$.check_duplicate?await $model$$.findOne({id_app:$obj$$.id_app,[$field$$]:$obj$$[$field$$]},{[$field$$]:1}).lean()?$count$$>=9?$callback$$(`Kh\u00f4ng th\u1ec3 t\u1ef1 \u0111\u1ed9ng t\u1ea1o gi\u00e1 tr\u1ecb cho field ${$field$$}. Gi\u00e1 tr\u1ecb "${$obj$$[$field$$]}" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ki\u1ec3m tra l\u1ea1i th\u00f4ng s\u1ed1 quy\u1ec3n ch\u1ee9ng t\u1eeb sao cho gi\u00e1 tr\u1ecb s\u1ebd t\u1ea1o ra kh\u00f4ng b\u1ecb tr\u00f9ng v\u1edbi gi\u00e1 tr\u1ecb \u0111\u00e3 c\u00f3`):
|
|
16
16
|
($count$$++,$callback$$()):($count$$=99999,$callback$$()):($count$$=99999,$callback$$())})},$_options$$)},function($err$$){$cb$$($err$$)})},$e$$=>{$callback$$($e$$)})})}).catch($e$$=>{Logger.error($e$$)})})},$callback$$=>{setImmediate(function(){if((!$voucher_options$$?.trang_thai_create_voucher_numbers||$voucher_options$$?.trang_thai_create_voucher_numbers.length==0||$voucher_options$$?.trang_thai_create_voucher_numbers?.indexOf($obj$$.trang_thai)>=0)&&$model$$.schema.paths.so_ct)if($obj$$.so_ct&&
|
|
17
17
|
$obj$$.so_ct.toUpperCase()!==($listinfo_code$$||$ctrl$$.name).toUpperCase()&&$obj$$.so_ct.toUpperCase()!==$ctrl$$.name.toUpperCase())$checkVoucherNumber$$($error$$=>{$callback$$($error$$)});else{let $count$$=0;async.whilst(function($cb$$){$cb$$(null,$count$$<100)},function($callback$$){getNextSequence($obj$$.id_app,$listinfo_code$$||$ctrl$$.name,"so_ct",function($e$$,$rs$$){setImmediate(()=>{if($e$$)return $callback$$($e$$);$obj$$.so_ct=$rs$$.so_ct;$checkVoucherNumber$$($error$$=>{$error$$?$count$$>=
|
|
18
18
|
99?$callback$$($error$$):($count$$++,$callback$$()):($count$$=99999,$callback$$())})})},$obj$$)},function($err$$){$callback$$($err$$)})}else $callback$$()})},function($callback$$){setImmediate(async()=>{if($model$$.schema.paths.ma_dvcs&&$ctrl$$.name!=="dvcs")if($obj$$.ma_dvcs)if(global.mongoose.Types.ObjectId.isValid($obj$$.ma_dvcs)){let $_id_dvcs$$=global.mongoose.Types.ObjectId($obj$$.ma_dvcs);await global.getModel("dvcs").findOne({_id:$_id_dvcs$$})?$callback$$():global.getModel("dvcs").create({_id:$_id_dvcs$$,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
const permission=require("../libs/permission"),{ERRORS}=require("./controllerUtils"),createRouteHandler=async($ctrl$$,$req$$,$callback$$)=>{let $res_send$$=!1;const {routeName:$routeName$$,route_action_key:$route_action_key$$,_options:$_options$$}=$req$$;if($ctrl$$.require_id_app===!1)try{$ctrl$$[$route_action_key$$]($req$$,function($e$$,$rs$$){if($res_send$$)return Logger.error("route",$routeName$$,"sent header. callback had call");if($e$$){Logger.error("create route",$routeName$$,$e$$);if($e$$.error)return $res_send$$=
|
|
2
|
-
!0,$callback$$($e$$);$res_send$$=!0;return $callback$$({error:$e$$.message||$e$$})}$res_send$$=!0;return $callback$$(null,$rs$$)})}catch($e$$){return Logger.error("route",$routeName$$,$e$$),$res_send$$=!0,$callback$$({error:$e$$.message||$e$$})}else{let $id_app$$=$req$$.params.id_app,$notNeedRight$$=$_options$$.notNeedRight||await $ctrl$$.notNeedRight($req$$.user);permission.hasRight($id_app$$,$req$$.user.email,$ctrl$$.module,$_options$$?.
|
|
2
|
+
!0,$callback$$($e$$);$res_send$$=!0;return $callback$$({error:$e$$.message||$e$$})}$res_send$$=!0;return $callback$$(null,$rs$$)})}catch($e$$){return Logger.error("route",$routeName$$,$e$$),$res_send$$=!0,$callback$$({error:$e$$.message||$e$$})}else{let $id_app$$=$req$$.params.id_app,$notNeedRight$$=$_options$$.notNeedRight||await $ctrl$$.notNeedRight($req$$.user);permission.hasRight($id_app$$,$req$$.user.email,$ctrl$$.module,$_options$$?.action_code||"view",function($error$$,$hr$$){if($res_send$$)return Logger.error("route",
|
|
3
3
|
$routeName$$,"sent header. hasRight had call");if($hr$$)try{$ctrl$$[$route_action_key$$]($req$$,function($e$$,$rs$$){$res_send$$&&Logger.error("route",$routeName$$,"sent header. callback had call");if($e$$){if($e$$.error)return $res_send$$=!0,$callback$$($e$$);$res_send$$=!0;return $callback$$({error:$e$$.message||$e$$})}$res_send$$=!0;return $callback$$(null,$rs$$)})}catch($e$$){return $res_send$$=!0,Logger.error("route",$routeName$$,$e$$),$callback$$({error:$e$$.message||$e$$})}else return $res_send$$=
|
|
4
4
|
!0,$callback$$({error:$error$$.error||$error$$||ERRORS.ERR_NOT_PERMIT,code:$error$$.code||ERRORS.ERR_NOT_PERMIT_CODE})},{notNeedRight:$notNeedRight$$})}};module.exports=createRouteHandler;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
const permission=require("../libs/permission"),createRouteHandler=async($ctrl$$,$req$$,$callback$$)=>{const {routeName:$routeName$$,route_action_key:$route_action_key$$,_options:$_options$$}=$req$$;let $notNeedRight$$=$_options$$.notNeedRight||await $ctrl$$.notNeedRight($req$$.user),$res_send$$=!1;if($ctrl$$.options.require_id_app===!1)try{$ctrl$$[$route_action_key$$]($req$$,function($e$$,$rs$$){if($res_send$$)return Logger.error("no id_app route",$routeName$$,"sent header. calback had call");if($e$$){Logger.error("handle create route ",
|
|
2
|
-
$routeName$$,$e$$);if($e$$.error)return $res_send$$=!0,$callback$$($e$$);$res_send$$=!0;return $callback$$({error:$e$$.message||$e$$})}$res_send$$=!0;return $callback$$(null,$rs$$)})}catch($e$$){return $res_send$$=!0,$callback$$({error:$e$$.message||$e$$})}else permission.hasRight($req$$.params.id_app,$req$$.user.email,$ctrl$$.module,$_options$$?.
|
|
2
|
+
$routeName$$,$e$$);if($e$$.error)return $res_send$$=!0,$callback$$($e$$);$res_send$$=!0;return $callback$$({error:$e$$.message||$e$$})}$res_send$$=!0;return $callback$$(null,$rs$$)})}catch($e$$){return $res_send$$=!0,$callback$$({error:$e$$.message||$e$$})}else permission.hasRight($req$$.params.id_app,$req$$.user.email,$ctrl$$.module,$_options$$?.action_code||"view",function($error$$,$hr$$){if($res_send$$)return Logger.error("route",$routeName$$,"sent header. hasRight had call");if($hr$$)try{$ctrl$$[$route_action_key$$]($req$$,
|
|
3
3
|
function($e$$,$rs$$){if($res_send$$)return Logger.error("route",$routeName$$,"sent header. calback had call");if($e$$){Logger.error("handle create route ",$routeName$$,$e$$);if($e$$.error)return $res_send$$=!0,$callback$$($e$$);$res_send$$=!0;return $callback$$({error:$e$$.message||$e$$})}$res_send$$=!0;return $callback$$(null,$rs$$)})}catch($e$$){return $callback$$({error:$e$$.message||$e$$})}else $res_send$$=!0,$callback$$({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xem b\u00e1o c\u00e1o n\u00e0y"})},
|
|
4
4
|
{notNeedRight:$notNeedRight$$})};module.exports=createRouteHandler;
|
|
@@ -6,22 +6,24 @@ $condition_kh_custs$$.nh_kh={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}}$con
|
|
|
6
6
|
Object.keys($condition_kh_custs$$).length>0&&($condition_kh_custs$$.id_app=$condition$$.id_app,$condition_kh_custs$$=await global.getModel("customer").find($condition_kh_custs$$,{ma_kh:1}).lean(),$query$$.ma_kh={$in:$condition_kh_custs$$.map($c$$=>$c$$.ma_kh)})}$condition$$.ma_ct&&($query$$.ma_ct=$condition$$.ma_ct);$condition$$.user_hoa_hong&&($query$$.$or?$query$$.$and=[{$or:[{user_nv:$condition$$.user_hoa_hong},{user_ctv:$condition$$.user_hoa_hong},{user_ctv2:$condition$$.user_hoa_hong},{user_kho:$condition$$.user_hoa_hong},
|
|
7
7
|
{user_gt:$condition$$.user_hoa_hong},{user_ql:$condition$$.user_hoa_hong},{"details.user_nv":$condition$$.user_hoa_hong},{"details.user_ctv":$condition$$.user_hoa_hong},{"details.user_ctv2":$condition$$.user_hoa_hong},{"details.user_kho":$condition$$.user_hoa_hong},{"details.user_gt":$condition$$.user_hoa_hong},{"details.user_ql":$condition$$.user_hoa_hong}]}]:$query$$.$or=[{user_nv:$condition$$.user_hoa_hong},{user_ctv:$condition$$.user_hoa_hong},{user_ctv2:$condition$$.user_hoa_hong},{user_kho:$condition$$.user_hoa_hong},
|
|
8
8
|
{user_gt:$condition$$.user_hoa_hong},{user_ql:$condition$$.user_hoa_hong},{"details.user_nv":$condition$$.user_hoa_hong},{"details.user_ctv":$condition$$.user_hoa_hong},{"details.user_ctv2":$condition$$.user_hoa_hong},{"details.user_kho":$condition$$.user_hoa_hong},{"details.user_gt":$condition$$.user_hoa_hong},{"details.user_ql":$condition$$.user_hoa_hong}]);databanle($query$$,async function($error$$,$rs$$,$ptthanhtoans$$){if($error$$)return $callback$$($error$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>
|
|
9
|
-
({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));$rs$$.forEach(function($r$$){$r$$.sl_dh=1;$r$$.thang=$r$$.ngay_ct.getMonth()+1;$r$$.nam=moment($r$$.ngay_ct).year();$r$$.quy=moment($r$$.ngay_ct).quarter()});async.
|
|
10
|
-
$r$$.details.csum("tien");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.tien_ck_hd=$r$$.tien_ck_hd||0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.t_tien_hoa_hong=$r$$.details.csum("tien_hoa_hong");$r$$.t_tien_hoa_hong_gt=$r$$.details.csum("tien_hoa_hong_gt");$r$$.t_tien_hoa_hong_ctv=$r$$.details.csum("tien_hoa_hong_ctv");$r$$.t_tien_hoa_hong_ql=$r$$.details.csum("tien_hoa_hong_ql");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.details_tl?
|
|
11
|
-
$r$$.details_tl.csum("tien_hang_ct")-$r$$.details_tl.csum("tien_ck"),$r$$.t_tien_thue_tl=$r$$.details_tl.csum("tien_thue"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap"),$r$$.t_tien_hoa_hong-=$r$$.details_tl.csum("tien_hoa_hong"),$r$$.t_tien_hoa_hong_gt-=$r$$.details_tl.csum("tien_hoa_hong_gt"),$r$$.t_tien_hoa_hong_ctv-=$r$$.details_tl.csum("tien_hoa_hong_ctv"),$r$$.t_tien_hoa_hong_ql-=$r$$.details_tl.csum("tien_hoa_hong_ql")):($r$$.t_tien_tl=
|
|
12
|
-
0,$r$$.t_tien_nhap=0)
|
|
13
|
-
|
|
14
|
-
value:"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
$date$jscomp$1_date$jscomp$2_date$jscomp$3_date
|
|
19
|
-
$
|
|
20
|
-
$r$$.
|
|
21
|
-
|
|
22
|
-
$
|
|
23
|
-
$r$$.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));$rs$$.forEach(function($r$$){$r$$.sl_dh=1;$r$$.thang=$r$$.ngay_ct.getMonth()+1;$r$$.nam=moment($r$$.ngay_ct).year();$r$$.quy=moment($r$$.ngay_ct).quarter()});async.mapLimit($rs$$,20,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_hang_ct=$r$$.details.csum("tien_hang_ct");$r$$.t_thue=$r$$.details.csum("tien_thue");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");
|
|
10
|
+
$r$$.t_tien=$r$$.details.csum("tien");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.tien_ck_hd=$r$$.tien_ck_hd||0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.t_tien_hoa_hong=$r$$.details.csum("tien_hoa_hong");$r$$.t_tien_hoa_hong_gt=$r$$.details.csum("tien_hoa_hong_gt");$r$$.t_tien_hoa_hong_ctv=$r$$.details.csum("tien_hoa_hong_ctv");$r$$.t_tien_hoa_hong_ql=$r$$.details.csum("tien_hoa_hong_ql");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.details_tl?
|
|
11
|
+
($r$$.t_tien_tl=$r$$.details_tl.csum("tien_hang_ct")-$r$$.details_tl.csum("tien_ck"),$r$$.t_tien_thue_tl=$r$$.details_tl.csum("tien_thue"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap"),$r$$.t_tien_hoa_hong-=$r$$.details_tl.csum("tien_hoa_hong"),$r$$.t_tien_hoa_hong_gt-=$r$$.details_tl.csum("tien_hoa_hong_gt"),$r$$.t_tien_hoa_hong_ctv-=$r$$.details_tl.csum("tien_hoa_hong_ctv"),$r$$.t_tien_hoa_hong_ql-=$r$$.details_tl.csum("tien_hoa_hong_ql")):($r$$.t_tien_tl=
|
|
12
|
+
0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);setImmediate(async()=>{if($r$$._id){var $da_thus_no$$=await global.getModel("tdttno").findOne({id_ct:$r$$._id}).lean();$da_thus_no$$&&($r$$.t_tien_no_nt=$da_thus_no$$.tien_nt,$r$$.t_tien_no=$da_thus_no$$.tien,$da_thus_no$$=await global.getModel("tdttno_tt").find({id_hd:$r$$._id}).lean(),$r$$.t_tien_da_thu=$da_thus_no$$.map($d$$=>$d$$.tien).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$r$$.t_tien_da_thu_nt=$da_thus_no$$.map($d$$=>$d$$.tien_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,
|
|
13
|
+
0));$r$$.t_tien_con_no=$r$$.t_tien_no-$r$$.t_tien_da_thu;$r$$.t_tien_con_no_nt=$r$$.t_tien_no_nt-$r$$.t_tien_da_thu_nt}$callback$$(null,$r$$)})},async function($error$$,$rs$$){if($error$$)return $callback$$($error$$);$error$$=[{name:"sl_dh",value:"sl_dh"},{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_hang_ct",value:"t_tien_hang_ct"},{name:"t_thue",value:"t_thue"},{name:"t_tien_cp",value:"t_tien_cp"},{name:"t_tien_ck",
|
|
14
|
+
value:"t_tien_ck"},{name:"t_tien",value:"t_tien"},{name:"tien_ck_hd",value:"tien_ck_hd"},{name:"tien_freeship",value:"tien_freeship"},{name:"tien_phi_vc",value:"tien_phi_vc"},{name:"tien_evoucher",value:"tien_evoucher"},{name:"tien_thu",value:"tien_thu"},{name:"tien_thu2",value:"tien_thu2"},{name:"tien_paymentByPoints",value:"tien_paymentByPoints"},{name:"t_tien_xuat",value:"t_tien_xuat"},{name:"t_tien_tl",value:"t_tien_tl"},{name:"t_tien_thue_tl",value:"t_tien_thue_tl"},{name:"t_tien_nhap",value:"t_tien_nhap"},
|
|
15
|
+
{name:"phai_tra",value:"phai_tra"},{name:"t_tien_hoa_hong",value:"t_tien_hoa_hong"},{name:"t_tien_hoa_hong_gt",value:"t_tien_hoa_hong_gt"},{name:"t_tien_hoa_hong_ctv",value:"t_tien_hoa_hong_ctv"},{name:"t_tien_hoa_hong_ql",value:"t_tien_hoa_hong_ql"},{name:"t_tien_da_thu",value:"t_tien_da_thu"},{name:"t_tien_con_no",value:"t_tien_con_no"},...$thanh_toan$$];let $data$$=await $rs$$.asyncGroupBy([...(new Set([...$group_by$$,"ma_kh"]))],$error$$);await $data$$.filter($r$$=>$r$$.ma_kh).asyncJoinModel2($condition$$.id_app,
|
|
16
|
+
"customer",{where:"ma_kh",fields:["ngay_mua_dau_tien",{cust_date_created:"date_created"}]});$data$$.forEach($r$$=>{$r$$.t_kh=1;if($r$$.cust_date_created){let $tu_ngay$$;switch($field_group_by$$){case "nam":var $date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=moment(new Date(Number($r$$.nam),1,1));$tu_ngay$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.startOf("year").toDate().getTime();$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.endOf("year").toDate().getTime();
|
|
17
|
+
break;case "quy":$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=moment(new Date(Number($r$$.nam),1,1));$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.quarters(Number($r$$.quy));$tu_ngay$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.startOf("quarters").toDate().getTime();$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.endOf("quarters").toDate().getTime();break;case "thang":$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=
|
|
18
|
+
moment(new Date(Number($r$$.nam),0,1));$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.month(Number($r$$.thang)-1);$tu_ngay$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.startOf("months").toDate().getTime();$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.endOf("months").toDate().getTime();break;case "ngay_ct":$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=moment($r$$.ngay_ct);$tu_ngay$$=
|
|
19
|
+
$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.startOf("dates").toDate().getTime();$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.endOf("dates").toDate().getTime();break;default:$tu_ngay$$=(new Date($condition$$.tu_ngay)).getTime(),$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=(new Date($condition$$.den_ngay)).getTime()}var $cust_created_ngay_mua_dau_tien$$=(new Date($r$$.ngay_mua_dau_tien)).getTime();$r$$.mua_lan_dau=$r$$.ngay_mua_dau_tien&&
|
|
20
|
+
$cust_created_ngay_mua_dau_tien$$>=$tu_ngay$$&&$cust_created_ngay_mua_dau_tien$$<=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$?1:0;$r$$.kh_cu=$r$$.ngay_mua_dau_tien&&$cust_created_ngay_mua_dau_tien$$<$tu_ngay$$?1:0;$cust_created_ngay_mua_dau_tien$$=(new Date($r$$.cust_date_created)).getTime();$r$$.kh_moi=$r$$.ngay_mua_dau_tien&&$cust_created_ngay_mua_dau_tien$$>=$tu_ngay$$&&$cust_created_ngay_mua_dau_tien$$<=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$?1:0}else $r$$.mua_lan_dau=0,$r$$.kh_moi=
|
|
21
|
+
0,$r$$.kh_cu=0});switch($condition$$.loai_kh){case "MUA_LAN_DAU":$data$$=$data$$.filter($c$$=>$c$$.mua_lan_dau);$rs$$=$rs$$.filter($r$$=>$data$$.find($c$$=>$c$$.ma_kh===$r$$.ma_kh));break;case "KH_MOI":$data$$=$data$$.filter($c$$=>$c$$.kh_moi);$rs$$=$rs$$.filter($r$$=>$data$$.find($c$$=>$c$$.ma_kh===$r$$.ma_kh));break;case "KH_CU":$data$$=$data$$.filter($c$$=>$c$$.kh_cu),$rs$$=$rs$$.filter($r$$=>$data$$.find($c$$=>$c$$.ma_kh===$r$$.ma_kh))}let $report$$=await $data$$.asyncGroupBy($group_by$$,[...$error$$,
|
|
22
|
+
"kh_moi","kh_cu","t_kh","sl_dh","mua_lan_dau"]);$report$$=$report$$.sort(($a$$,$b$$)=>{for(let $i$$=0;$i$$<$group_by$$.length;$i$$++){let $field$$=$group_by$$[$i$$],$a_v$$=$a$$[$field$$],$b_v$$=$b$$[$field$$];$field$$=="ngay_ct"&&($a_v$$=moment($a_v$$).format("YYYY-MM-DD"),$b_v$$=moment($b_v$$).format("YYYY-MM-DD"));if($a_v$$<$b_v$$)return-1;if($a_v$$>$b_v$$)return 1}return 0});$report$$.forEach(function($r$$,$i$$){$r$$.stt=$i$$+1;$r$$.bold=!1;$r$$.t_phai_thu=$r$$.t_tien_hang_ct-($r$$.t_tien_ck||
|
|
23
|
+
0)+($r$$.t_thue||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0)-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu=$r$$.t_tien_hang_ct-($r$$.t_tien_ck||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0)-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-($r$$.t_tien_tl-$r$$.t_tien_nhap)-($r$$.t_tien_cp||0);$r$$.t_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.name]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,
|
|
24
|
+
0);$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$r$$.nam?($i$$=moment(new Date($r$$.nam,0,1)),$r$$.quy?($i$$=$i$$.quarter($r$$.quy),$r$$.tu_ngay=$i$$.startOf("quarter").toDate(),$r$$.den_ngay=$i$$.endOf("quarter").toDate()):$r$$.thang?($i$$=$i$$.month($r$$.thang-1),$r$$.tu_ngay=$i$$.startOf("month").toDate(),$r$$.den_ngay=$i$$.endOf("month").toDate()):($r$$.tu_ngay=$i$$.startOf("year").toDate(),$r$$.den_ngay=$i$$.endOf("year").toDate())):($r$$.tu_ngay=$condition$$.tu_ngay,$r$$.den_ngay=
|
|
25
|
+
$condition$$.den_ngay)});await $report$$.filter($r$$=>$r$$.ma_kh).asyncJoinModel2($condition$$.id_app,"customer",{where:"ma_kh",fields:"ten_kh"});await $report$$.filter($r$$=>$r$$.ma_kho).asyncJoinModel2($condition$$.id_app,"dmkho",{where:"ma_kho",fields:"ten_kho"});const $tong_cong$$={[$group_by$$[0]]:"T\u1ed5ng c\u1ed9ng",mua_lan_dau:$report$$.csum("mua_lan_dau"),kh_moi:$report$$.csum("kh_moi"),kh_cu:$report$$.csum("kh_cu"),t_kh:$report$$.csum("t_kh"),sl_dh:$report$$.csum("sl_dh"),t_sl_xuat:$report$$.csum("t_sl_xuat"),
|
|
26
|
+
t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_hang:$report$$.csum("t_tien_hang"),t_tien_hang_ct:$report$$.csum("t_tien_hang_ct"),t_thue:$report$$.csum("t_thue"),t_tien_cp:$report$$.csum("t_tien_cp"),t_tien_ck:$report$$.csum("t_tien_ck"),t_tien:$report$$.csum("t_tien"),tien_ck_hd:$report$$.csum("tien_ck_hd"),tien_phi_vc:$report$$.csum("tien_phi_vc"),tien_freeship:$report$$.csum("tien_freeship"),t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_thue_tl:$report$$.csum("t_tien_thue_tl"),t_tien_xuat:$report$$.csum("t_tien_xuat"),
|
|
27
|
+
t_tien_nhap:$report$$.csum("t_tien_nhap"),t_phai_thu:$report$$.csum("t_phai_thu"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_doanh_thu_thuan:$report$$.csum("t_doanh_thu_thuan"),tien_evoucher:$report$$.csum("tien_evoucher"),tien_thu:$report$$.csum("tien_thu"),tien_thu2:$report$$.csum("tien_thu2"),t_tien_thu:$report$$.csum("t_tien_thu"),phai_tra:$report$$.csum("phai_tra"),t_tien_paymentByPoints:$report$$.csum("tien_paymentByPoints"),t_lai:$report$$.csum("t_lai"),t_tien_hoa_hong:$report$$.csum("t_tien_hoa_hong"),
|
|
28
|
+
t_tien_hoa_hong_gt:$report$$.csum("t_tien_hoa_hong_gt"),t_tien_hoa_hong_ctv:$report$$.csum("t_tien_hoa_hong_ctv"),t_tien_hoa_hong_ql:$report$$.csum("t_tien_hoa_hong_ql"),t_tien_da_thu:$report$$.csum("t_tien_da_thu"),t_tien_con_no:$report$$.csum("t_tien_con_no"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.name]=$report$$.csum($pt$$.name)});$report$$.push($tong_cong$$);$report$$.forEach($r$$=>{$r$$.t_tien_phai_tl=$r$$.t_tien_tl+$r$$.t_tien_thue_tl});$callback$$(null,{data:$report$$,
|
|
29
|
+
thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})};
|
|
@@ -10,39 +10,40 @@ code:-1},!1);$callback$$(null,$participant$$.admin,$app$$,$participant$$)}).catc
|
|
|
10
10
|
exports.hasRight=async function($current_id_app$$,$email$$,$module$$,$action$$,$callbackMain$$,$options$$={}){if(!$current_id_app$$||$options$$.notNeedRight)return $callbackMain$$(null,!0);const $model$$=global.controllers[$module$$]?global.controllers[$module$$].model:void 0;if($model$$&&$model$$.schema&&!underscore.has($model$$.schema.paths,"id_app"))return $callbackMain$$(null,!0);let $right_code$$=($options$$.right_code||$options$$.listinfo_code||$module$$).toLowerCase();$options$$.data&&($options$$.data.trang_thai||
|
|
11
11
|
$options$$.data.trang_thai==0)&&($options$$.data.trang_thai=$options$$.data.trang_thai.toString());$options$$.obj&&($options$$.obj.trang_thai||$options$$.obj.trang_thai==0)&&($options$$.obj.trang_thai=$options$$.obj.trang_thai.toString());$action$$=($action$$||"").toLowerCase();var $data$$=$options$$.data||$options$$.obj||{};const $ma_ct$$=$model$$&&underscore.has($model$$.schema.paths,"ma_ct")&&(($options$$.obj||{}).ma_ct||($options$$.data||{}).ma_ct||"").toString().toUpperCase();let $ma_trang_thai$$=
|
|
12
12
|
($data$$.trang_thai||$data$$.progress||"").toString().toUpperCase();!$ma_trang_thai$$&&$options$$.obj&&($ma_trang_thai$$=($options$$.obj.trang_thai||$options$$.obj.progress||"").toString().toUpperCase());if($ma_ct$$&&$ma_trang_thai$$)if($data$$=await trangthai.findOne({ma_trang_thai:$ma_trang_thai$$,ma_ct:$ma_ct$$}).lean()){if($data$$.not_need_right)return $callbackMain$$(null,!0)}else Logger.info("Khong tim thay trang thai cho chuc nang nay",{ma_ct:$ma_ct$$,ma_trang_thai:$ma_trang_thai$$,trang_thai:$data$$,
|
|
13
|
-
action:$action$$});exports.isAdmin($current_id_app$$,$email$$,async($
|
|
14
|
-
|
|
15
|
-
$
|
|
13
|
+
action:$action$$});exports.isAdmin($current_id_app$$,$email$$,async($e_model$$,$admin$$,$app$$,$_right__right_trang_thai_controler_participant$$)=>{if($e_model$$)return $callbackMain$$($e_model$$,!1);if(!$admin$$&&$right_code$$!=$module$$.toLowerCase()){var $key_right_listinfo_ms_q$$=await global.getModel("listinfo").findOne({code:$right_code$$}).lean();if(!$key_right_listinfo_ms_q$$)return $callbackMain$$({error:`M\u00e3 quy\u1ec1n '${$right_code$$}' kh\u00f4ng t\u1ed3n t\u1ea1i`});if(($key_right_listinfo_ms_q$$.api_code||
|
|
14
|
+
$key_right_listinfo_ms_q$$.code)!=$module$$.toLowerCase())return $callbackMain$$({error:`M\u00e3 quy\u1ec1n '${$right_code$$}' kh\u00f4ng h\u1ee3p l\u1ec7`})}$e_model$$=$key_right_listinfo_ms_q$$?.permistion_code||$right_code$$;if($app$$&&$app$$.allow_modules&&$app$$.allow_modules.length>0&&($key_right_listinfo_ms_q$$={"items.code":{$regex:"^"+$module$$+"$",$options:"i"},active_require:!0},$app$$.menu_code&&($key_right_listinfo_ms_q$$.app=$app$$.menu_code),$key_right_listinfo_ms_q$$=await global.getModel("moduleinfo").find($key_right_listinfo_ms_q$$).lean(),
|
|
15
|
+
$key_right_listinfo_ms_q$$.length>0&&$key_right_listinfo_ms_q$$.filter($m$$=>$app$$.allow_modules.indexOf($m$$.code)>=0&&(!$m$$.not_for_companies||$m$$.not_for_companies.indexOf($app$$._id.toString())<0)&&(!$m$$.only_for_companies||$m$$.only_for_companies.indexOf($app$$._id.toString())>=0)).length==0))return $callbackMain$$('API "'+$module$$+'" ch\u01b0a \u0111\u01b0\u1ee3c k\u00edch ho\u1ea1t cho c\u00f4ng ty n\u00e0y (trong module '+$key_right_listinfo_ms_q$$[0].app+"/"+$key_right_listinfo_ms_q$$[0].title+
|
|
16
16
|
")",!1);if($options$$.data&&$options$$.data.id_app){if($options$$.data.id_app!=$current_id_app$$)return $callbackMain$$("B\u1ea1n kh\u00f4ng th\u1ec3 truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);if($options$$.obj&&$options$$.data.id_app!=$options$$.obj.id_app)return $callbackMain$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1)}if($options$$.obj&&$options$$.obj.id_app&&$options$$.obj.id_app!=$current_id_app$$)return $callbackMain$$("B\u1ea1n kh\u00f4ng th\u1ec3 truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",
|
|
17
17
|
!1);if($options$$.notNeedRight)return $callbackMain$$(null,!0,$app$$);if($options$$.obj&&!$admin$$)if($options$$.obj.visible_to===2){if(!underscore.contains($options$$.obj.visible_to_users,$email$$)&&$options$$.obj.of_user!==$email$$.toLowerCase()&&$options$$.obj.user_created&&$options$$.obj.user_created.toLowerCase()!==$email$$.toLowerCase())return $callbackMain$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1)}else if($options$$.obj.visible_to===
|
|
18
18
|
1&&$options$$.obj.of_user!==$email$$.toLowerCase()&&$options$$.obj.user_created&&$options$$.obj.user_created.toLowerCase()!==$email$$.toLowerCase()&&$options$$.obj.phu_trach!=$email$$.toLowerCase()&&($options$$.obj.attends||[]).indexOf($email$$)<0&&(await exports.dsDangPhuTrach($options$$.obj.id_app,$email$$.toLowerCase())).indexOf($options$$.obj.user_created)<0)return $callbackMain$$("Ch\u1ec9 ng\u01b0\u1eddi t\u1ea1o, ph\u1ee5 tr\u00e1ch, h\u1ed7 tr\u1ee3 v\u00e0 admin m\u1edbi c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",
|
|
19
|
-
!1);$
|
|
20
|
-
$
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
$
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
$
|
|
19
|
+
!1);$key_right_listinfo_ms_q$$=$email$$;$_right__right_trang_thai_controler_participant$$&&$_right__right_trang_thai_controler_participant$$.group_id&&($key_right_listinfo_ms_q$$=$_right__right_trang_thai_controler_participant$$.group_id.toLowerCase());($_right__right_trang_thai_controler_participant$$=await right.findOne({id_app:$current_id_app$$,email:$key_right_listinfo_ms_q$$,module:$e_model$$}).lean())||$e_model$$!=$options$$.listinfo_code||$e_model$$==$module$$.toLowerCase()||($e_model$$=$module$$.toLowerCase());
|
|
20
|
+
$_right__right_trang_thai_controler_participant$$=await right.findOne({id_app:$current_id_app$$,email:$key_right_listinfo_ms_q$$,module:$e_model$$}).lean();if(!$admin$$){if(!$_right__right_trang_thai_controler_participant$$)return $_right__right_trang_thai_controler_participant$$=global.controllers[$module$$.toUpperCase()],$e_model$$=(($_right__right_trang_thai_controler_participant$$||{}).model_name||$module$$).toLowerCase(),$e_model$$=="customer"||$e_model$$.indexOf("socai")>=0||$e_model$$.indexOf("sokho")>=
|
|
21
|
+
0||$e_model$$.indexOf("vatvao")>=0||$e_model$$.indexOf("vatra")>=0||$e_model$$.indexOf("tdttno")>=0||$e_model$$.indexOf("tdttco")>=0||$_right__right_trang_thai_controler_participant$$&&($_right__right_trang_thai_controler_participant$$.options||{}).isVoucher||$action$$!=="view"&&($action$$!=="add"||$module$$.toLowerCase()!=="group")?$callbackMain$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",!1):($_right__right_trang_thai_controler_participant$$={"items.code":$module$$.toLowerCase()},
|
|
22
|
+
$app$$&&$app$$.menu_code&&($_right__right_trang_thai_controler_participant$$.app=$app$$.menu_code),await global.getModel("moduleinfo").findOne($_right__right_trang_thai_controler_participant$$,{app:1}).lean()?$callbackMain$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",!1):$callbackMain$$(null,!0,$app$$));if($action$$=="view"&&$_right__right_trang_thai_controler_participant$$?.view_all)return $callbackMain$$(null,!0,$app$$);if($action$$=="view"&&$options$$.obj&&
|
|
23
|
+
$_right__right_trang_thai_controler_participant$$&&!$_right__right_trang_thai_controler_participant$$.view_all&&!$_right__right_trang_thai_controler_participant$$.viewOfOther&&$options$$.obj.user_created.toLowerCase()!==$email$$&&($options$$.obj.visible_to!==2||!underscore.contains($options$$.obj.visible_to_users,$email$$))&&$options$$.obj.phu_trach!==$email$$&&($options$$.obj.attends||[]).indexOf($email$$)<0&&(await exports.dsDangPhuTrach($options$$.obj.id_app,$email$$.toLowerCase())).indexOf($options$$.obj.user_created)<
|
|
24
|
+
0)return $callbackMain$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);if(!$_right__right_trang_thai_controler_participant$$[$action$$])return $callbackMain$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",!1);if($ma_trang_thai$$&&($_right__right_trang_thai_controler_participant$$=$_right__right_trang_thai_controler_participant$$[`${$action$$}_trang_thai`])&&!$_right__right_trang_thai_controler_participant$$[$ma_trang_thai$$]&&
|
|
25
|
+
$_right__right_trang_thai_controler_participant$$[$ma_trang_thai$$]!=void 0)return $callbackMain$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y",!1)}$options$$.obj?async.series({trangthai:$callback$$=>{$options$$.obj&&($action$$==="update"||$action$$==="delete")&&$model$$&&underscore.has($model$$.schema.paths,"ma_ct")&&$options$$.obj.ma_ct?trangthai.findOne({ma_ct:$options$$.obj.ma_ct.toUpperCase(),ma_trang_thai:$options$$.obj.trang_thai},
|
|
26
|
+
function($e$$,$trang_thai$$){if($e$$)return $callback$$($e$$);if($trang_thai$$){if($action$$==="update"){if($trang_thai$$.allow_update==0)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p s\u1eeda");if($trang_thai$$.lock_data==1)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c kho\u00e1")}if($action$$==="delete"&&($trang_thai$$.lock_data||$trang_thai$$.allow_delete==0))return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p xo\u00e1")}return $callback$$()}):
|
|
27
|
+
$callback$$()}},$action_right_e$$=>{if($action_right_e$$)$callbackMain$$($action_right_e$$,!1);else{$action_right_e$$=`${$action$$}_right`;if(!$admin$$&&$options$$.obj&&$options$$.obj[$action_right_e$$]&&$options$$.obj[$action_right_e$$].length>0&&$options$$.obj[$action_right_e$$].indexOf($email$$.toLowerCase())<0)return $callbackMain$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",!1);$callbackMain$$(null,!0,$app$$)}}):$callbackMain$$(null,!0,$app$$)},
|
|
27
28
|
$options$$)};
|
|
28
29
|
exports.getRightByItem=async function($id_app$$,$model$$,$email$$,$next$$,$module$$,$options$$={}){$module$$||=$model$$&&$model$$.modelName?$model$$.modelName.toLowerCase():"";let $right_code$$=($options$$.right_code||$options$$.listinfo_code||$module$$).toLowerCase(),$key_cache$$=$right_code$$?`RightByItem::${$id_app$$}::${$email$$}::${$right_code$$}::${JSON.stringify($options$$)}`:"",$time_cache$$=$email$$==="public"?10080:1;if($key_cache$$&&global.cacheDatas[$key_cache$$]&&moment().diff(moment(global.cacheDatas[$key_cache$$].time),"minutes")<
|
|
29
|
-
$time_cache$$)return $next$$(null,global.cacheDatas[$key_cache$$].data,!1);exports.isAdmin($id_app$$,$email$$,async function($condition_e$$,$admin
|
|
30
|
-
await global.getModel("listinfo").findOne({code:$right_code$$}).lean();if(!$
|
|
31
|
-
$_right_trang_thai$jscomp$1_participant$$.group_id&&($
|
|
32
|
-
$_right$$.view_all){if($_right$$&&$_right$$.extra_condition)try{$condition_e$$=evalute(`return ${$_right$$.extra_condition}`,{module:$module$$,participant:$_right_trang_thai$jscomp$1_participant$$,appInfo:$allow_trang_thai_app$$})}catch($e$$){return Logger.error("[getRightByItem] [extra_condition]"
|
|
33
|
-
await exports.dsDangPhuTrach($id_app$$,$email$$);$
|
|
34
|
-
underscore.has($model$$.schema.paths,"
|
|
35
|
-
|
|
36
|
-
"trang_thai")===!0){if($_right_trang_thai$jscomp$1_participant$$=$_right$$.view_trang_thai){$allow_trang_thai_app$$=[void 0,null,""];for(var $t_viewOfOther_right_trang_thai$$ in $_right_trang_thai$jscomp$1_participant$$)$_right_trang_thai$jscomp$1_participant$$[$t_viewOfOther_right_trang_thai$$]
|
|
37
|
-
[void 0,null,""];for(var $t$jscomp$1_users$$ in $t_viewOfOther_right_trang_thai$$)!$t_viewOfOther_right_trang_thai$$[$t$jscomp$1_users$$]||$_right_trang_thai$jscomp$1_participant$$&&!$_right_trang_thai$jscomp$1_participant$$[$t$jscomp$1_users$$]
|
|
38
|
-
{email:1}).lean(),$
|
|
39
|
-
|
|
40
|
-
($
|
|
41
|
-
|
|
42
|
-
underscore.has($model$$.schema.paths,"
|
|
43
|
-
($condition_e$$.$and=[]),$allUsers_query$$={visible_to:0},$selUsers$$={visible_to:2,visible_to_users:$email$$},$_right_trang_thai$jscomp$1_participant$$=underscore.has($model$$.schema.paths,"visible_to_usergroups")?{visible_to:5,visible_to_usergroups:($_right_trang_thai$jscomp$1_participant$$||
|
|
44
|
-
$admin$jscomp$
|
|
45
|
-
$condition_e$$.$or&&$condition_e$$.$or.length===0&&delete $condition_e$$.$or;$key_cache$$&&(global.cacheDatas[$key_cache$$]={time:new Date,data:_.cloneDeep($condition_e$$)});$next$$(null,$condition_e$$,!1)}},$options$$)};
|
|
30
|
+
$time_cache$$)return $next$$(null,global.cacheDatas[$key_cache$$].data,!1);exports.isAdmin($id_app$$,$email$$,async function($condition_e$$,$admin$$,$allow_trang_thai_app$$,$_right_trang_thai$jscomp$1_participant$$){if($condition_e$$)return $next$$($condition_e$$);$condition_e$$={};if($admin$$||$options$$.notNeedRight||!underscore.has($model$$.schema.paths,"id_app"))$next$$(null,$condition_e$$,$admin$$);else{if($right_code$$&&$right_code$$!=$module$$.toLowerCase()){var $_right$jscomp$1_listinfo$$=
|
|
31
|
+
await global.getModel("listinfo").findOne({code:$right_code$$}).lean();if(!$_right$jscomp$1_listinfo$$)return $next$$({error:`M\u00e3 quy\u1ec1n '${$right_code$$}' kh\u00f4ng t\u1ed3n t\u1ea1i`});if(($_right$jscomp$1_listinfo$$.api_code||$_right$jscomp$1_listinfo$$.code)!=$module$$.toLowerCase())return $next$$({error:`M\u00e3 quy\u1ec1n '${$right_code$$}' kh\u00f4ng h\u1ee3p l\u1ec7`})}var $ds_dang_phu_trach_permistion_code$$=$_right$jscomp$1_listinfo$$?.permistion_code||$right_code$$;let $selUsers$$;
|
|
32
|
+
$admin$$=[];let $key_right$$=$email$$;$_right_trang_thai$jscomp$1_participant$$&&$_right_trang_thai$jscomp$1_participant$$.group_id&&($key_right$$=$_right_trang_thai$jscomp$1_participant$$.group_id.toLowerCase());($_right$jscomp$1_listinfo$$=await right.findOne({id_app:$id_app$$,email:$key_right$$,module:$ds_dang_phu_trach_permistion_code$$}).lean())||$ds_dang_phu_trach_permistion_code$$!=$options$$.listinfo_code||$ds_dang_phu_trach_permistion_code$$==$module$$.toLowerCase()||($ds_dang_phu_trach_permistion_code$$=
|
|
33
|
+
$module$$.toLowerCase());if(($_right$jscomp$1_listinfo$$=await right.findOne({id_app:$id_app$$,email:$key_right$$,module:$ds_dang_phu_trach_permistion_code$$}).lean())&&$_right$jscomp$1_listinfo$$.view_all){if($_right$jscomp$1_listinfo$$&&$_right$jscomp$1_listinfo$$.extra_condition)try{$condition_e$$=evalute(`return ${$_right$jscomp$1_listinfo$$.extra_condition}`,{module:$module$$,participant:$_right_trang_thai$jscomp$1_participant$$,appInfo:$allow_trang_thai_app$$})}catch($e$$){return Logger.error("[getRightByItem] [extra_condition]",
|
|
34
|
+
$e$$,$_right$jscomp$1_listinfo$$.extra_condition),$next$$($e$$.message)}$key_cache$$&&(global.cacheDatas[$key_cache$$]={time:new Date,data:_.cloneDeep($condition_e$$)});return $next$$(null,$condition_e$$,!1)}$ds_dang_phu_trach_permistion_code$$=await exports.dsDangPhuTrach($id_app$$,$email$$);$ds_dang_phu_trach_permistion_code$$.push($email$$);$_right$jscomp$1_listinfo$$&&$_right$jscomp$1_listinfo$$.view_empty_phu_trach&&($ds_dang_phu_trach_permistion_code$$.push(""),$ds_dang_phu_trach_permistion_code$$.push(null));
|
|
35
|
+
if($_right$jscomp$1_listinfo$$&&$_right$jscomp$1_listinfo$$.view){$allow_trang_thai_app$$={visible_to:null};if(underscore.has($model$$.schema.paths,"visible_to")){$condition_e$$.$and||($condition_e$$.$and=[]);var $allUsers_query$$={visible_to:0};$selUsers$$={visible_to:2,visible_to_users:$email$$};$_right_trang_thai$jscomp$1_participant$$=underscore.has($model$$.schema.paths,"visible_to_usergroups")?{visible_to:5,visible_to_usergroups:($_right_trang_thai$jscomp$1_participant$$||{}).group_id}:{visible_to:5,
|
|
36
|
+
visible_to_users:($_right_trang_thai$jscomp$1_participant$$||{}).group_id};$admin$$.push($allUsers_query$$);$admin$$.push($selUsers$$);$admin$$.push($_right_trang_thai$jscomp$1_participant$$);$admin$$.push($allow_trang_thai_app$$)}if($_right$jscomp$1_listinfo$$.viewOfOther===!1){if(underscore.has($model$$.schema.paths,"ma_kh")){var $allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$=await exports.dsKhDangPhuTrach($id_app$$,{$in:$ds_dang_phu_trach_permistion_code$$});$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$.length>
|
|
37
|
+
0&&$admin$$.push({ma_kh:{$in:$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$}})}$allUsers_query$$?$allUsers_query$$.user_created={$in:$ds_dang_phu_trach_permistion_code$$}:$admin$$.push({user_created:{$in:$ds_dang_phu_trach_permistion_code$$}})}else{if(underscore.has($model$$.schema.paths,"trang_thai")===!0){if($_right_trang_thai$jscomp$1_participant$$=$_right$jscomp$1_listinfo$$.view_trang_thai){$allow_trang_thai_app$$=[void 0,null,""];for(var $t_viewOfOther_right_trang_thai$$ in $_right_trang_thai$jscomp$1_participant$$)$_right_trang_thai$jscomp$1_participant$$[$t_viewOfOther_right_trang_thai$$]&&
|
|
38
|
+
$allow_trang_thai_app$$.push($t_viewOfOther_right_trang_thai$$);$condition_e$$.trang_thai={$in:$allow_trang_thai_app$$}}if($t_viewOfOther_right_trang_thai$$=$_right$jscomp$1_listinfo$$.viewOfOther_trang_thai){$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$=[void 0,null,""];for(var $t$jscomp$1_users$$ in $t_viewOfOther_right_trang_thai$$)!$t_viewOfOther_right_trang_thai$$[$t$jscomp$1_users$$]||$_right_trang_thai$jscomp$1_participant$$&&!$_right_trang_thai$jscomp$1_participant$$[$t$jscomp$1_users$$]||
|
|
39
|
+
$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$.push($t$jscomp$1_users$$)}}$_right$jscomp$1_listinfo$$.viewOfOther_user_groups&&$_right$jscomp$1_listinfo$$.viewOfOther_user_groups.length>0?($t$jscomp$1_users$$=await Participant.find({id_app:$id_app$$,group_id:{$in:$_right$jscomp$1_listinfo$$.viewOfOther_user_groups}},{email:1}).lean(),$ds_dang_phu_trach_permistion_code$$.push(...$t$jscomp$1_users$$.map($u$$=>$u$$.email)),$allUsers_query$$?$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$?
|
|
40
|
+
$allUsers_query$$.$or=[{user_created:{$in:$ds_dang_phu_trach_permistion_code$$.filter($e$$=>$e$$!=$email$$)},trang_thai:{$in:$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$}},{user_created:$email$$}]:$allUsers_query$$.user_created={$in:$ds_dang_phu_trach_permistion_code$$}:$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$?($admin$$.push({user_created:{$in:$ds_dang_phu_trach_permistion_code$$},trang_thai:{$in:$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$}}),
|
|
41
|
+
$admin$$.push({$or:[{user_created:{$in:$ds_dang_phu_trach_permistion_code$$.filter($e$$=>$e$$!=$email$$)},trang_thai:{$in:$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$}},{user_created:$email$$}]})):$admin$$.push({user_created:{$in:$ds_dang_phu_trach_permistion_code$$}})):$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$&&($allUsers_query$$?$allUsers_query$$.$or=[{user_created:{$ne:$email$$},trang_thai:{$in:$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$}},
|
|
42
|
+
{user_created:$email$$}]:$admin$$.push({$or:[{user_created:{$ne:$email$$},trang_thai:{$in:$allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$}},{user_created:$email$$}]}))}$selUsers$$&&(underscore.has($model$$.schema.paths,"of_user")&&$admin$$.push({of_user:$email$$}),underscore.has($model$$.schema.paths,"phu_trach")&&$admin$$.push({phu_trach:{$in:$ds_dang_phu_trach_permistion_code$$}}),underscore.has($model$$.schema.paths,"attends")&&$admin$$.push({attends:{$in:$ds_dang_phu_trach_permistion_code$$}}))}else not_need_right_models.indexOf($module$$)<
|
|
43
|
+
0&&($admin$$.push({user_created:$email$$}),underscore.has($model$$.schema.paths,"of_user")&&$admin$$.push({of_user:$email$$}),underscore.has($model$$.schema.paths,"phu_trach")&&$admin$$.push({phu_trach:{$in:$ds_dang_phu_trach_permistion_code$$}}),underscore.has($model$$.schema.paths,"attends")&&$admin$$.push({attends:$email$$})),$allUsers_query$$={"items.code":$module$$.toLowerCase()},$allow_trang_thai_app$$&&$allow_trang_thai_app$$.menu_code&&($allUsers_query$$.app=$allow_trang_thai_app$$.menu_code),
|
|
44
|
+
await global.getModel("moduleinfo").findOne($allUsers_query$$,{app:1}).lean()||($allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$={visible_to:null},underscore.has($model$$.schema.paths,"visible_to")&&($condition_e$$.$and||($condition_e$$.$and=[]),$allUsers_query$$={visible_to:0},$selUsers$$={visible_to:2,visible_to_users:$email$$},$_right_trang_thai$jscomp$1_participant$$=underscore.has($model$$.schema.paths,"visible_to_usergroups")?{visible_to:5,visible_to_usergroups:($_right_trang_thai$jscomp$1_participant$$||
|
|
45
|
+
{}).group_id}:{visible_to:5,visible_to_users:($_right_trang_thai$jscomp$1_participant$$||{}).group_id},$admin$$.push($allUsers_query$$),$admin$$.push($selUsers$$),$admin$$.push($_right_trang_thai$jscomp$1_participant$$),$admin$$.push($allow_viewOfOther_trang_thai_ds_kh_dang_phu_trach_visible_to_null$$)));underscore.has($model$$.schema.paths,"public")&&$admin$$.push({public:!0});underscore.has($model$$.schema.paths,"shared")&&$admin$$.push({shared:!0});$admin$$.length>0&&($condition_e$$.$and||($condition_e$$.$and=
|
|
46
|
+
[]),$condition_e$$.$and.push({$or:$admin$$}));$condition_e$$.$and&&$condition_e$$.$and.length===0&&delete $condition_e$$.$and;$condition_e$$.$or&&$condition_e$$.$or.length===0&&delete $condition_e$$.$or;$key_cache$$&&(global.cacheDatas[$key_cache$$]={time:new Date,data:_.cloneDeep($condition_e$$)});$next$$(null,$condition_e$$,!1)}},$options$$)};
|
|
46
47
|
exports.getRightDataView=function($id_app$$,$model$$,$email$$,$next$$){exports.isAdmin($id_app$$,$email$$,function($condition$jscomp$1_e$$,$admin$$){if($condition$jscomp$1_e$$)return $next$$($condition$jscomp$1_e$$);$condition$jscomp$1_e$$={};if(!$admin$$&&underscore.has($model$$.schema.paths,"dataview_to_users")===!0){$condition$jscomp$1_e$$.$and||($condition$jscomp$1_e$$.$and=[]);let $dataview$$=[{dataview_to:null}];$dataview$$.push({dataview_to:0});$dataview$$.push({dataview_to:1,user_created:$email$$});
|
|
47
48
|
$dataview$$.push({dataview_to:2,dataview_to_users:$email$$});$condition$jscomp$1_e$$.$and.push({$or:$dataview$$})}$next$$(null,$condition$jscomp$1_e$$,$admin$$)})};
|
|
48
49
|
exports.getFieldNotRight=async($_fields_id_app$$,$_p_email$jscomp$5_group_id$$,$ma_ct$$)=>{if(!$_fields_id_app$$)return[];$_p_email$jscomp$5_group_id$$=await Participant.ofApp($_fields_id_app$$,$_p_email$jscomp$5_group_id$$);if($_p_email$jscomp$5_group_id$$.length>0){$_p_email$jscomp$5_group_id$$=$_p_email$jscomp$5_group_id$$[0].group_id;let $field_not_right$$;try{$field_not_right$$=await right.getInfo($_fields_id_app$$,{email:$_p_email$jscomp$5_group_id$$,module:$ma_ct$$.toLowerCase()},"field_not_right")}catch($e$$){return[]}$_fields_id_app$$=
|