flexbiz-server 12.1.22 → 12.1.23

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "flexbiz-server",
3
3
  "main": "./server/app.js",
4
4
  "description": "Flexible Server",
5
- "version": "12.1.22",
5
+ "version": "12.1.23",
6
6
  "author": {
7
7
  "name": "Van Truong Pham",
8
8
  "email": "invncur@gmail.com"
@@ -1,4 +1,4 @@
1
- 'use strict';const User=global.getModel("user"),Participant=global.getModel("participant"),UserGroup=global.getModel("usergroup"),Customer=global.getModel("customer"),request=require("request"),log=global.getModel("log"),App=global.getModel("app"),Wallet=global.getModel("wallet"),Token=global.getModel("token"),BasicStrategy=require("passport-http").BasicStrategy,_crypto=require("crypto"),validator=require("validator"),email=require("../libs/email"),loadTemplate=require("../libs/load-template"),permission=
1
+ 'use strict';const User=global.getModel("user"),Participant=global.getModel("participant"),UserGroup=global.getModel("usergroup"),Customer=global.getModel("customer"),axios=require("axios"),log=global.getModel("log"),App=global.getModel("app"),Wallet=global.getModel("wallet"),Token=global.getModel("token"),BasicStrategy=require("passport-http").BasicStrategy,_crypto=require("crypto"),validator=require("validator"),email=require("../libs/email"),loadTemplate=require("../libs/load-template"),permission=
2
2
  require("../libs/permission"),OTP=global.getModel("otp"),DIGITS="0123456789",jwt=require("jsonwebtoken"),redisCache=require("../libs/redis-cache");function generateOTP(){let $OTP$$="";for(let $i$$=0;6>$i$$;$i$$++)$OTP$$+=DIGITS[Math.floor(10*Math.random())];return $OTP$$}
3
3
  function generateToken($user$$){var $body_n_n$$={email:$user$$.email};configs.APP_SECRET?jwt.sign({user:$body_n_n$$},configs.APP_SECRET):($body_n_n$$=new Date,_crypto.createHash("md5").update($user$$.email+$body_n_n$$.toISOString()).digest("hex"));$body_n_n$$=new Date;return _crypto.createHash("md5").update($user$$.email+$body_n_n$$.toISOString()).digest("hex")}
4
4
  function saveOTP($Phone$$,$otp_code$$,$callback$$,$expires$$=5){let $expire_time$$=new Date;$expire_time$$.setMinutes($expire_time$$.getMinutes()+$expires$$);OTP.create({phone:$Phone$$,otp:$otp_code$$,expire_time:$expire_time$$},($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$callback$$(null,$rs$$.toObject())})}
@@ -10,15 +10,15 @@ $username$$+" ch\u01b0a \u0111\u01b0\u1ee3c \u0111\u0103ng k\u00fd.");if(0==$use
10
10
  $user$$.email,$rs$$)});else{if(!$user$$.validPassword($password$$))return $done$$("M\u1eadt kh\u1ea9u kh\u00f4ng ch\u00ednh x\u00e1c.")}else{if(!$user$$.local.password)return $done$$("M\u1eadt kh\u1ea9u cho ng\u01b0\u1eddi d\u00f9ng n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i. H\u00e3y s\u1eed d\u1ee5ng t\u00ednh n\u0103ng kh\u00f4i ph\u1ee5c m\u1eadt kh\u1ea9u \u0111\u1ec3 \u0111\u1eb7t l\u1ea1i m\u1eadt kh\u1ea9u cho ng\u01b0\u1eddi d\u00f9ng n\u00e0y");if(!$user$$.validPassword($password$$))return $done$$("M\u1eadt kh\u1ea9u kh\u00f4ng ch\u00ednh x\u00e1c.")}return $done$$(null,
11
11
  $user$$)})})}));$app$jscomp$0$$.get("/send-otp/:address_receive_otp",$rateLimiter$$,async($req_url$$,$res$$)=>{if(configs.GOOGLE_RECAPTCHA_SECRET_KEY){if(!$req_url$$.query["g-recaptcha-response"])return $res$$.status(400).send("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u m\u1ed9t google recaptcha token");try{await permission.verifyReCaptcha($req_url$$.query["g-recaptcha-response"])}catch($e$$){return $res$$.status(400).send($e$$.messag||$e$$.error||$e$$)}}let $address_receive_otp$$=$req_url$$.params.address_receive_otp.trim().toLowerCase(),
12
12
  $u$$=await User.findOne({$or:[{email:$address_receive_otp$$},{"local.phone":$address_receive_otp$$}]});if(!$u$$)return $res$$.status(400).send({error:`T\u00e0i kho\u1ea3n ${$address_receive_otp$$} kh\u00f4ng t\u1ed3n t\u1ea1i`});const $username$$=$u$$.email,$otp_code$$=generateOTP();let $phone$$;$address_receive_otp$$!=$username$$&&validator.isMobilePhone($address_receive_otp$$)?$phone$$=$address_receive_otp$$:validator.isMobilePhone($username$$)?$phone$$=$username$$:validator.isMobilePhone(($u$$.local||
13
- {}).phone||"")&&($phone$$=($u$$.local||{}).phone);if($phone$$)configs.sms.send?configs.sms.send($phone$$,$otp_code$$,$req_url$$.query.id_app).then($rs$jscomp$0$$=>{$rs$jscomp$0$$.error_message?$res$$.status(400).send({error:$rs$jscomp$0$$.message||$rs$jscomp$0$$.error||$rs$jscomp$0$$.error_message||`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`}):saveOTP($username$$,$otp_code$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);
14
- $res$$.send($rs$$)})}).catch($e$$=>{console.error("Error send sms",$e$$);$res$$.status(400).send({error:$e$$.message||$e$$.error_message||`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`})}):($req_url$$=configs.sms.genUrlSendOTP($phone$$,$otp_code$$,$req_url$$.query.id_app),request({url:$req_url$$},($error$$,$response$$,$body$$)=>{if($error$$||200!=$response$$.statusCode)$res$$.status(400).send({error:$error$$||`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`});
15
- else try{const $info$$=JSON.parse($body$$);"100"==$info$$.CodeResult?saveOTP($username$$,$otp_code$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)}):(console.error("Error send sms",$info$$),$res$$.status(400).send({error:`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`}))}catch($e$$){$res$$.status(400).send({error:$body$$})}}));else{let $email_address$$;validator.isEmail($address_receive_otp$$)&&$address_receive_otp$$!=
16
- $username$$?$email_address$$=$address_receive_otp$$:validator.isEmail($username$$)?$email_address$$=$username$$:$u$$.email2&&validator.isEmail($u$$.email2)&&($email_address$$=$u$$.email2);$email_address$$?email.sendHtml({to:{address:$email_address$$},subject:"M\u00e3 x\u00e1c th\u1ef1c",html:`Xin vui l\u00f2ng g\u1eedi qu\u00fd kh\u00e1ch m\u00e3 x\u00e1c th\u1ef1c: ${$otp_code$$}. M\u00e3 n\u00e0y s\u1ebd h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng sau 5 ph\u00fat.`},function($error$$){$error$$?(console.error("Error send otp to email",
17
- $error$$),$res$$.status(400).send(`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi email ${$username$$}`)):saveOTP($username$$,$otp_code$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)},5)},configs.sender_otp):$res$$.status(400).send({error:`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`})}});$app$jscomp$0$$.get("/verify-otp/:id/:otp",$rateLimiter$$,async function($req$$,$res$$){try{const $id$$=
18
- $req$$.params.id;if(!global.mongoose.Types.ObjectId.isValid($id$$))return $res$$.status(400).send({error:"ID c\u1ee7a m\u00e3 x\u00e1c th\u1ef1c n\u00e0y kh\u00f4ng h\u1ee3p l\u1ec7",code:4001});const $otp_code$$=$req$$.params.otp,$otp$$=await OTP.findById($id$$);if(!$otp$$)return $res$$.status(400).send({error:"M\u00e3 x\u00e1c th\u1ef1c n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i",code:4001});$otp$$.tried_number=($otp$$.tried_number||0)+1;await $otp$$.save();if($otp$$.otp!=$otp_code$$||$otp$$.verified||
19
- $otp$$.tried_number>(configs.MAX_TRY_OTP||3)||$otp$$.expire_time.getTime()<(new Date).getTime())return $res$$.status(400).send({error:"M\u00e3 x\u00e1c th\u1ef1c n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i ho\u1eb7c \u0111\u00e3 h\u1ebft hi\u1ec7u l\u1ef1c",code:4001});await OTP.findOneAndUpdate({_id:$id$$},{verified:!0});let $user$$=await User.findOne({email:$otp$$.phone});if(!$user$$)return $res$$.status(400).send({error:"T\u00e0i kho\u1ea3n kh\u00f4ng t\u1ed3n t\u1ea1i",code:4001});if(!$user$$.local||
20
- !$user$$.local.active){$user$$.local=$user$$.local||{};$user$$.local.active=!0;try{await $user$$.save(),redisCache.set("user",$user$$.toObject(),function($e$$){$e$$?console.error($e$$):console.log("cache user infomation to redis")})}catch($e$$){return console.log("error verify otp, create user",$e$$),$res$$.status(500).send($e$$)}}const $accessToken$$=generateToken($user$$);(new Token({email:$user$$.email,session_created:($req$$.cookies||{}).uid,token:$accessToken$$,agent:$req$$.headers["user-agent"],
21
- ip:"",once:1==$req$$.query.once||"true"==$req$$.query.once||"1"===$req$$.query.once?!0:!1})).save(function($e$$,$rs$$){return $e$$?$res$$.status(500).send($e$$):$res$$.send({token:$accessToken$$,once:$rs$$.once})})}catch($e$$){console.error("error verify otp",$e$$),$res$$.status(400).send($e$$.message)}});$app$jscomp$0$$.post("/auth/sign",$rateLimiter$$,($req$$,$res$$,$next$$)=>{$passport$$.authenticate("basic",{session:!1},function($err$$,$user$$){if($err$$||!$user$$)return $res$$.status(401).send({message:$err$$||
13
+ {}).phone||"")&&($phone$$=($u$$.local||{}).phone);if($phone$$)if(configs.sms&&(configs.sms.send||configs.sms.genUrlSendOTP))if(configs.sms.send)configs.sms.send($phone$$,$otp_code$$,$req_url$$.query.id_app).then($rs$jscomp$0$$=>{$rs$jscomp$0$$.error_message?$res$$.status(400).send({error:$rs$jscomp$0$$.message||$rs$jscomp$0$$.error||$rs$jscomp$0$$.error_message||`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`}):saveOTP($username$$,$otp_code$$,
14
+ ($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)})}).catch($e$$=>{console.error("Error send sms",$e$$);$res$$.status(400).send({error:$e$$.message||$e$$.error_message||`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`})});else if($req_url$$=configs.sms.genUrlSendOTP($phone$$,$otp_code$$,$req_url$$.query.id_app))try{await axios.get($req_url$$),saveOTP($username$$,$otp_code$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);
15
+ $res$$.send($rs$$)})}catch($e$$){console.error($e$$),$res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$||`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`})}else $res$$.status(400).send({error:`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`});else $res$$.status(400).send({error:`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`});
16
+ else{let $email_address$$;validator.isEmail($address_receive_otp$$)&&$address_receive_otp$$!=$username$$?$email_address$$=$address_receive_otp$$:validator.isEmail($username$$)?$email_address$$=$username$$:$u$$.email2&&validator.isEmail($u$$.email2)&&($email_address$$=$u$$.email2);$email_address$$?email.sendHtml({to:{address:$email_address$$},subject:"M\u00e3 x\u00e1c th\u1ef1c",html:`Xin vui l\u00f2ng g\u1eedi qu\u00fd kh\u00e1ch m\u00e3 x\u00e1c th\u1ef1c: ${$otp_code$$}. M\u00e3 n\u00e0y s\u1ebd h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng sau 5 ph\u00fat.`},
17
+ function($error$$){$error$$?(console.error("Error send otp to email",$error$$),$res$$.status(400).send(`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi email ${$username$$}`)):saveOTP($username$$,$otp_code$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)},5)},configs.sender_otp):$res$$.status(400).send({error:`Kh\u00f4ng th\u1ec3 g\u1eedi \u0111\u01b0\u1ee3c m\u00e3 OTP t\u1edbi t\u00e0i kho\u1ea3n ${$username$$}`})}});$app$jscomp$0$$.get("/verify-otp/:id/:otp",
18
+ $rateLimiter$$,async function($req$$,$res$$){try{const $id$$=$req$$.params.id;if(!global.mongoose.Types.ObjectId.isValid($id$$))return $res$$.status(400).send({error:"ID c\u1ee7a m\u00e3 x\u00e1c th\u1ef1c n\u00e0y kh\u00f4ng h\u1ee3p l\u1ec7",code:4001});const $otp_code$$=$req$$.params.otp,$otp$$=await OTP.findById($id$$);if(!$otp$$)return $res$$.status(400).send({error:"M\u00e3 x\u00e1c th\u1ef1c n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i",code:4001});$otp$$.tried_number=($otp$$.tried_number||0)+1;await $otp$$.save();
19
+ if($otp$$.otp!=$otp_code$$||$otp$$.verified||$otp$$.tried_number>(configs.MAX_TRY_OTP||3)||$otp$$.expire_time.getTime()<(new Date).getTime())return $res$$.status(400).send({error:"M\u00e3 x\u00e1c th\u1ef1c n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i ho\u1eb7c \u0111\u00e3 h\u1ebft hi\u1ec7u l\u1ef1c",code:4001});await OTP.findOneAndUpdate({_id:$id$$},{verified:!0});let $user$$=await User.findOne({email:$otp$$.phone});if(!$user$$)return $res$$.status(400).send({error:"T\u00e0i kho\u1ea3n kh\u00f4ng t\u1ed3n t\u1ea1i",
20
+ code:4001});if(!$user$$.local||!$user$$.local.active){$user$$.local=$user$$.local||{};$user$$.local.active=!0;try{await $user$$.save(),redisCache.set("user",$user$$.toObject(),function($e$$){$e$$?console.error($e$$):console.log("cache user infomation to redis")})}catch($e$$){return console.log("error verify otp, create user",$e$$),$res$$.status(500).send($e$$)}}const $accessToken$$=generateToken($user$$);(new Token({email:$user$$.email,session_created:($req$$.cookies||{}).uid,token:$accessToken$$,
21
+ agent:$req$$.headers["user-agent"],ip:"",once:1==$req$$.query.once||"true"==$req$$.query.once||"1"===$req$$.query.once?!0:!1})).save(function($e$$,$rs$$){return $e$$?$res$$.status(500).send($e$$):$res$$.send({token:$accessToken$$,once:$rs$$.once})})}catch($e$$){console.error("error verify otp",$e$$),$res$$.status(400).send($e$$.message)}});$app$jscomp$0$$.post("/auth/sign",$rateLimiter$$,($req$$,$res$$,$next$$)=>{$passport$$.authenticate("basic",{session:!1},function($err$$,$user$$){if($err$$||!$user$$)return $res$$.status(401).send({message:$err$$||
22
22
  "Unauthorized"});$req$$.user=$user$$;$next$$()})($req$$,$res$$,$next$$)},async($req$jscomp$3_user$$,$res$$)=>{let $data$$=$req$jscomp$3_user$$.body;$req$jscomp$3_user$$=$req$jscomp$3_user$$.user;if(!$data$$)return $res$$.status(400).send("Not have data to sign");if(!$data$$.id_app)return $res$$.status(400).send("Data miss id_app property");try{let $signature$$=await Wallet.sign($data$$.id_app,$req$jscomp$3_user$$.email,$data$$);$res$$.send($signature$$)}catch($e$$){return $res$$.status(400).send($e$$.message||
23
23
  $e$$)}});$app$jscomp$0$$.get("/auth/local",$rateLimiter$$,function($req$$,$res$$,$next$$){let $ip$$=($req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress).split(".").join("").split(":").join(""),$authorization$$=$req$$.headers.authorization;if(!$authorization$$)return $res$$.status(400).send({message:"Authorization is required"});$authorization$$=Buffer.from($authorization$$.replace("Basic ",""),"base64").toString("utf-8");$authorization$$=$authorization$$.split(":");if(1<
24
24
  $authorization$$.length){let $t_session$$="times_login_"+$ip$$+"_"+$authorization$$[0].trim().toLowerCase(),$d_session$$="datetime_login_"+$ip$$+"_"+$authorization$$[0].trim().toLowerCase();$req$$.t_session=$t_session$$;$req$$.d_session=$d_session$$;let $now$$=new Date,$d$$=$now$$,$times_try$$=1;if($req$$.headers.cookie&&$req$$.session){$req$$=$req$$.session;$req$$[$t_session$$]?($times_try$$=$req$$[$t_session$$]+1,$req$$[$t_session$$]=$times_try$$):($req$$[$t_session$$]=$times_try$$,$req$$[$d_session$$]=
@@ -121,17 +121,24 @@ exports.onepay_configs= {
121
121
  domestic: true//thanh trong nuoc hay ngoai nuoc
122
122
  }
123
123
  //sms configs
124
- exports.sms = {
125
- genUrlSendOTP:(Phone,otp_code)=>{
124
+ /*exports.sms = {
125
+ send: async (Phone,otp_code,id_app)=>{
126
126
  let Brandname="";
127
127
  let Content =`Xin vui long gui Quy Khach ma xac thuc: ${otp_code}`;
128
128
  let ApiKey = "";
129
129
  let SecretKey = "";
130
130
  let SmsType ="2";
131
131
  let url = ``
132
- return url;
132
+ const axios = require('axios');
133
+ try{
134
+ let rs = await axios.get(url)
135
+ return rs.data;
136
+ }catch(e){
137
+ console.error(e);
138
+ throw e.message;
139
+ }
133
140
  }
134
- }
141
+ }*/
135
142
  //oauth2.0
136
143
  exports.google = {
137
144
  clientID: '',
package/server/global.js CHANGED
@@ -2,11 +2,11 @@
2
2
  global.socketContainer={loadConnectionId:async()=>new Promise($res$$=>{global.clientRedis.get("client-io",function($err$$,$reply$$){if($err$$)return console.error($err$$),$res$$({});if($reply$$)try{let $ios$$=JSON.parse($reply$$);return $res$$($ios$$||{})}catch($e$$){return console.error($e$$),$res$$({})}else return $res$$({})})}),saveConnectionId:async($clientIO$$={})=>new Promise(($res$$,$rej$$)=>{global.clientRedis.set("client-io",JSON.stringify($clientIO$$),$e$$=>{if($e$$)return console.error($e$$),
3
3
  $rej$$($e$$);$res$$($clientIO$$)})})};global.clientIO={};global.model_books="socai sokho sokhott sokhokhongton sosanxuat vatvao vatra vsocai socaitmp".split(" ");global.webPush=require("web-push");global.mongoose=require("mongoose");global.mongoose.plugin(leanID);global.mongoose.plugin(deletePost);global.Schema=global.mongoose.Schema;global.mongoose.set("useFindAndModify",!1);global.mongoose.set("useCreateIndex",!0);
4
4
  global.getModel=$model_name$$=>{$model_name$$=$model_name$$.split(".js")[0];"kbmpttct"===$model_name$$&&($model_name$$="kbmPttct");"kbmtkgtgt"===$model_name$$&&($model_name$$="kbmTkgtgt");"token"===$model_name$$&&($model_name$$="tokens");"bn1"===$model_name$$&&($model_name$$="pc1");"bc1"===$model_name$$&&($model_name$$="pt1");var $_requireFields_model_model_path_mySchema$$=mongoose.models[$model_name$$];if($_requireFields_model_model_path_mySchema$$)return $_requireFields_model_model_path_mySchema$$;
5
- $_requireFields_model_model_path_mySchema$$=(((global.configs||{}).paths||{}).models||"./models")+"/"+$model_name$$+".js";if(fs.existsSync($_requireFields_model_model_path_mySchema$$))return require($_requireFields_model_model_path_mySchema$$);$_requireFields_model_model_path_mySchema$$=__dirname+"/models/"+$model_name$$+".js";if(fs.existsSync($_requireFields_model_model_path_mySchema$$))return require($_requireFields_model_model_path_mySchema$$);console.error("model",$model_name$$,"is not exists. create new model");
6
- $_requireFields_model_model_path_mySchema$$={...require("./models/listinfo").requireFields};$_requireFields_model_model_path_mySchema$$=new global.Schema($_requireFields_model_model_path_mySchema$$,{strict:!1});return global.mongoose.model($model_name$$,$_requireFields_model_model_path_mySchema$$)};global.getLib=$lib_name$$=>require("./libs/"+$lib_name$$);
7
- const pointSchema=new global.mongoose.Schema({type:{type:String,enum:["Point"],required:!0,default:"Point"},coordinates:{type:[Number],required:!0}}),polygonSchema=new global.mongoose.Schema({type:{type:String,enum:["Polygon"],required:!0,default:"Polygon"},coordinates:{type:[[[Number]]],required:!0}});global.customTypes={Point:pointSchema,Polygon:polygonSchema};const EventEmitter=require("events");class GlobalEmitter extends EventEmitter{}global.globalEvents=new GlobalEmitter;
8
- const Message=global.getModel("message"),Notification=global.getModel("notification"),User=global.getModel("user"),Sysconfig=global.getModel("sysconfig");global.getSysConfig=async $cf_code$$=>{if($cf_code$$=await Sysconfig.findOne({code:$cf_code$$}))return $cf_code$$.value};global.asyncCountUnRead=async $email$$=>new Promise($resolve$$=>{setImmediate(()=>{Message.countDocuments({email:$email$$,read:!1},($e$$,$rs$$)=>{$resolve$$($rs$$||0)})})});
9
- global.alertMessage=function($email$$){setImmediate(()=>{Message.countDocuments({email_owner:$email$$,email_receiver:$email$$,read:!1},function($error$$,$count$$){$error$$?console.log($error$$):User.emitEvent($email$$,"message:count",$count$$,!1)})})};
5
+ if(((global.configs||{}).paths||{}).models&&($_requireFields_model_model_path_mySchema$$=((global.configs||{}).paths||{}).models+"/"+$model_name$$+".js",fs.existsSync($_requireFields_model_model_path_mySchema$$)))return"dmdvt"==$model_name$$&&console.log("path dmdvt",$_requireFields_model_model_path_mySchema$$),require($_requireFields_model_model_path_mySchema$$);$_requireFields_model_model_path_mySchema$$=__dirname+"/models/"+$model_name$$+".js";if(fs.existsSync($_requireFields_model_model_path_mySchema$$))return"dmdvt"==
6
+ $model_name$$&&console.log("path dmdvt",$_requireFields_model_model_path_mySchema$$),require($_requireFields_model_model_path_mySchema$$);console.error("model",$model_name$$,"is not exists. create new model");$_requireFields_model_model_path_mySchema$$={...require("./models/listinfo").requireFields};$_requireFields_model_model_path_mySchema$$=new global.Schema($_requireFields_model_model_path_mySchema$$,{strict:!1});return global.mongoose.model($model_name$$,$_requireFields_model_model_path_mySchema$$)};
7
+ global.getLib=$lib_name$$=>require("./libs/"+$lib_name$$);const pointSchema=new global.mongoose.Schema({type:{type:String,enum:["Point"],required:!0,default:"Point"},coordinates:{type:[Number],required:!0}}),polygonSchema=new global.mongoose.Schema({type:{type:String,enum:["Polygon"],required:!0,default:"Polygon"},coordinates:{type:[[[Number]]],required:!0}});global.customTypes={Point:pointSchema,Polygon:polygonSchema};const EventEmitter=require("events");
8
+ class GlobalEmitter extends EventEmitter{}global.globalEvents=new GlobalEmitter;const Message=global.getModel("message"),Notification=global.getModel("notification"),User=global.getModel("user"),Sysconfig=global.getModel("sysconfig");global.getSysConfig=async $cf_code$$=>{if($cf_code$$=await Sysconfig.findOne({code:$cf_code$$}))return $cf_code$$.value};
9
+ global.asyncCountUnRead=async $email$$=>new Promise($resolve$$=>{setImmediate(()=>{Message.countDocuments({email:$email$$,read:!1},($e$$,$rs$$)=>{$resolve$$($rs$$||0)})})});global.alertMessage=function($email$$){setImmediate(()=>{Message.countDocuments({email_owner:$email$$,email_receiver:$email$$,read:!1},function($error$$,$count$$){$error$$?console.log($error$$):User.emitEvent($email$$,"message:count",$count$$,!1)})})};
10
10
  global.createNotification=function($email_sender$$,$email_receiver$$,$title$$,$content$$,$fn$$,$exfields$$,$emitEvent$$,$c_token$$,$send_email$$){Notification.createNotification($email_sender$$,$email_receiver$$,$title$$,$content$$,$fn$$,$exfields$$,$emitEvent$$,$c_token$$,$send_email$$)};
11
11
  global.getNotifies=function($email$$,$fn$$){async.parallel({colls:function($callback$$){$callback$$(null,[])},notifications:function($callback$$){Notification.find({email_receiver:$email$$,email_owner:$email$$,read:!1},function($error$$,$colls_raw$$){setImmediate(()=>{if($error$$)$callback$$($error$$);else{const $colls$$=$colls_raw$$.map(function($c$$){return $c$$.toObject()});$callback$$(null,$colls$$)}})})},apps:function($callback$$){$callback$$(null,[])}},function($error$$,$rs$$){setImmediate(()=>
12
12
  {$fn$$($error$$,$rs$$)})})};global.sendNotification=function($email$$,$_id$$,$notify$$,$push_to_mobile_and_web$$=!0){setImmediate(()=>{$notify$$||($notify$$={email_sender:"H\u1ec7 th\u1ed1ng"});const $obj_notify$$={_id:$_id$$,code:"notification",action:"view"};$obj_notify$$.body=$notify$$.content||$notify$$.title||"";$obj_notify$$.sender=$notify$$.email_sender;$obj_notify$$.title=$notify$$.title||"";$obj_notify$$.content=$notify$$.content||"";User.emitEvent($email$$,"notify:new",$obj_notify$$,$push_to_mobile_and_web$$)})};
@@ -1 +1 @@
1
- 'use strict';const Account=global.getModel("account");exports.checkAccAndCust=function($id_app$$,$tk$$,$ma_kh$$,$fn$$){$ma_kh$$||($ma_kh$$="");if(""!==$ma_kh$$.trim())return $fn$$();Account.findOne({id_app:$id_app$$,tk:$tk$$},{tk_cn:1,_id:0},function($error$$,$acc$$){return $error$$?$fn$$($error$$):$acc$$?!0===$acc$$.tk_cn?$fn$$(Error("T\u00e0i kho\u1ea3n "+$tk$$+" y\u00eau c\u1ea7u m\u1ed9t m\u00e3 kh\u00e1ch")):$fn$$():$fn$$(Error("T\u00e0i kho\u1ea3n "+$tk$$+" kh\u00f4ng t\u1ed3n t\u1ea1i"))})};
1
+ 'use strict';exports.checkAccAndCust=function($id_app$$,$tk$$,$ma_kh$$,$fn$$){$ma_kh$$||($ma_kh$$="");if(""!==$ma_kh$$.trim())return $fn$$();global.getModel("account").findOne({id_app:$id_app$$,tk:$tk$$},{tk_cn:1,_id:0},function($error$$,$acc$$){return $error$$?$fn$$($error$$):$acc$$?!0===$acc$$.tk_cn?$fn$$(Error("T\u00e0i kho\u1ea3n "+$tk$$+" y\u00eau c\u1ea7u m\u1ed9t m\u00e3 kh\u00e1ch")):$fn$$():$fn$$(Error("T\u00e0i kho\u1ea3n "+$tk$$+" kh\u00f4ng t\u1ed3n t\u1ea1i"))})};
@@ -1,4 +1,4 @@
1
- 'use strict';const Account=global.getModel("account");exports.isTkcn=[function($id_app$$,$tk$$,$callback$$){$tk$$?($tk$$=$tk$$.trim(),Account.findOne({id_app:$id_app$$,tk:$tk$$},{tk_cn:1,_id:0,loai_tk:1},function($error$$,$acc$$){$error$$||!$acc$$||0===$acc$$.loai_tk?$callback$$(!1):$callback$$($acc$$.tk_cn)})):$callback$$(!0)},"T\u00e0i kho\u1ea3n {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i ho\u1eb7c kh\u00f4ng ph\u1ea3i l\u00e0 t\u00e0i kho\u1ea3n c\u00f4ng n\u1ee3"];
2
- exports.isNotTkcn=[function($id_app$$,$tk$$,$callback$$){$tk$$?($tk$$=$tk$$.trim(),Account.findOne({id_app:$id_app$$,tk:$tk$$},{tk_cn:1,_id:0,loai_tk:1},function($error$$,$acc$$){$error$$||!$acc$$||0===$acc$$.loai_tk?$callback$$(!1):$callback$$(!$acc$$.tk_cn)})):$callback$$(!0)},"T\u00e0i kho\u1ea3n {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i ho\u1eb7c kh\u00f4ng ph\u1ea3i l\u00e0 t\u00e0i kho\u1ea3n c\u00f4ng n\u1ee3"];
3
- exports.existsTk=[function($id_app$$,$tk$$,$callback$$){$tk$$?($tk$$=$tk$$.trim(),Account.findOne({id_app:$id_app$$,tk:$tk$$},{tk:1,loai_tk:1},function($error$$,$acc$$){$error$$&&console.log($error$$);$acc$$||console.log("not found "+$tk$$+" of app "+$id_app$$);$error$$||!$acc$$||0===$acc$$.loai_tk?$callback$$(!1):$callback$$(!0)})):$callback$$(!0)},"T\u00e0i kho\u1ea3n {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
4
- exports.existsAnyTk=[function($id_app$$,$tk$$,$callback$$){$tk$$?($tk$$=$tk$$.trim(),Account.findOne({id_app:$id_app$$,tk:$tk$$},{tk:1},function($error$$,$acc$$){$error$$||!$acc$$||0===$acc$$.loai_tk?$callback$$(!1):$callback$$(!0)})):$callback$$(!0)},"T\u00e0i kho\u1ea3n {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
1
+ 'use strict';exports.isTkcn=[function($id_app$$,$tk$$,$callback$$){$tk$$?($tk$$=$tk$$.trim(),global.getModel("account").findOne({id_app:$id_app$$,tk:$tk$$},{tk_cn:1,_id:0,loai_tk:1},function($error$$,$acc$$){$error$$||!$acc$$||0===$acc$$.loai_tk?$callback$$(!1):$callback$$($acc$$.tk_cn)})):$callback$$(!0)},"T\u00e0i kho\u1ea3n {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i ho\u1eb7c kh\u00f4ng ph\u1ea3i l\u00e0 t\u00e0i kho\u1ea3n c\u00f4ng n\u1ee3"];
2
+ exports.isNotTkcn=[function($id_app$$,$tk$$,$callback$$){$tk$$?($tk$$=$tk$$.trim(),global.getModel("account").findOne({id_app:$id_app$$,tk:$tk$$},{tk_cn:1,_id:0,loai_tk:1},function($error$$,$acc$$){$error$$||!$acc$$||0===$acc$$.loai_tk?$callback$$(!1):$callback$$(!$acc$$.tk_cn)})):$callback$$(!0)},"T\u00e0i kho\u1ea3n {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i ho\u1eb7c kh\u00f4ng ph\u1ea3i l\u00e0 t\u00e0i kho\u1ea3n c\u00f4ng n\u1ee3"];
3
+ exports.existsTk=[function($id_app$$,$tk$$,$callback$$){$tk$$?($tk$$=$tk$$.trim(),global.getModel("account").findOne({id_app:$id_app$$,tk:$tk$$},{tk:1,loai_tk:1},function($error$$,$acc$$){$error$$&&console.log($error$$);$acc$$||console.log("not found "+$tk$$+" of app "+$id_app$$);$error$$||!$acc$$||0===$acc$$.loai_tk?$callback$$(!1):$callback$$(!0)})):$callback$$(!0)},"T\u00e0i kho\u1ea3n {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
4
+ exports.existsAnyTk=[function($id_app$$,$tk$$,$callback$$){$tk$$?($tk$$=$tk$$.trim(),global.getModel("account").findOne({id_app:$id_app$$,tk:$tk$$},{tk:1},function($error$$,$acc$$){$error$$||!$acc$$||0===$acc$$.loai_tk?$callback$$(!1):$callback$$(!0)})):$callback$$(!0)},"T\u00e0i kho\u1ea3n {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
@@ -1,2 +1,2 @@
1
- 'use strict';const Dmvt=global.getModel("dmvt"),Dmkho=global.getModel("dmkho");exports.existsVt=[function($id_app$$,$ma_vt$$,$callback$$){$ma_vt$$?Dmvt.findOne({id_app:$id_app$$,ma_vt:$ma_vt$$},{ma_vt:1},function($error$$,$vt$$){$error$$||!$vt$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 v\u1eadt t\u01b0 {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
2
- exports.existsKho=[function($id_app$$,$ma_kho$$,$callback$$){$ma_kho$$?Dmkho.findOne({id_app:$id_app$$,ma_kho:$ma_kho$$},{ma_kho:1},function($error$$,$kho$$){$error$$||!$kho$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 kho {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
1
+ 'use strict';exports.existsVt=[function($id_app$$,$ma_vt$$,$callback$$){$ma_vt$$?global.getModel("dmvt").findOne({id_app:$id_app$$,ma_vt:$ma_vt$$},{ma_vt:1},function($error$$,$vt$$){$error$$||!$vt$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 v\u1eadt t\u01b0 {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
2
+ exports.existsKho=[function($id_app$$,$ma_kho$$,$callback$$){$ma_kho$$?global.getModel("dmkho").findOne({id_app:$id_app$$,ma_kho:$ma_kho$$},{ma_kho:1},function($error$$,$kho$$){$error$$||!$kho$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 kho {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
@@ -1,11 +1,10 @@
1
- 'use strict';const Customer=global.getModel("customer"),Dvcs=global.getModel("dvcs"),Dmdvt=global.getModel("dmdvt"),Vat=global.getModel("vat"),Currency=global.getModel("currency"),Dmbp=global.getModel("dmbp"),Dmloaits=global.getModel("dmloaits"),Dmnguonvon=global.getModel("dmnguonvon"),Dmtanggiamts=global.getModel("dmtanggiamts"),app=global.getModel("app");
2
- exports.unlockBook=[async function($id_app$$,$ngay_ct$$,$callback$$,$options$$={}){if(!$ngay_ct$$)return $callback$$(!0);app.findOne({_id:$id_app$$},{ngay_ks:1,_id:0},function($error$$,$r$$){if($error$$||!$r$$||$r$$.ngay_ks.getTime()>=$ngay_ct$$.getTime()||$options$$.ngay_ks&&(new Date($options$$.ngay_ks)).getTime()>=$ngay_ct$$.getTime())return $callback$$(!1);$callback$$(!0)})},"\u0110\u00e3 kh\u00f3a s\u1ed5"];
3
- exports.existsKh=[function($id_app$$,$kh$$,$callback$$){if(!$kh$$)return $callback$$(!0);Customer.findOne({id_app:$id_app$$,ma_kh:$kh$$},{ma_kh:1},function($error$$,$cust$$){return $error$$||!$cust$$?$callback$$(!1):$callback$$(!0)})},"M\u00e3 kh\u00e1ch ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
4
- exports.existsDvcs=[function($id_app$$,$ma_dvcs$$,$callback$$){if(!$ma_dvcs$$)return $callback$$(!0);Dvcs.findOne({id_app:$id_app$$,_id:$ma_dvcs$$},function($error$$,$dvcs$$){return $error$$||!$dvcs$$?$callback$$(!1):$callback$$(!0)})},"M\u00e3 \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
5
- exports.existsNt=[function($id_app$$,$ma_nt$$,$callback$$){$ma_nt$$?Currency.findOne({id_app:$id_app$$,ma_nt:$ma_nt$$},function($error$$,$nt$$){return $error$$||!$nt$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 ngo\u1ea1i t\u1ec7 ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
6
- exports.existsDvt=[function($id_app$$,$ma_dvt$$,$callback$$){$ma_dvt$$?Dmdvt.findOne({id_app:$id_app$$,ma_dvt:$ma_dvt$$},function($error$$,$dvt$$){return $error$$||!$dvt$$?(console.log("check dvt",$error$$,$dvt$$,$id_app$$,$ma_dvt$$),$callback$$(!1)):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 \u0111\u01a1n v\u1ecb t\u00ednh ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
7
- exports.existsVat=[function($id_app$$,$ma_thue$$,$callback$$){$ma_thue$$?Vat.findOne({id_app:$id_app$$,ma_thue:$ma_thue$$},function($error$$,$v$$){return $error$$||!$v$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 thu\u1ebf ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
8
- exports.existsBp=[function($id_app$$,$ma_bp$$,$callback$$){$ma_bp$$?Dmbp.findOne({id_app:$id_app$$,ma_bp:$ma_bp$$},function($error$$,$v$$){return $error$$||!$v$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 b\u1ed9 ph\u1eadn ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
9
- exports.existsLts=[function($id_app$$,$ma_loai_ts$$,$callback$$){$ma_loai_ts$$?Dmloaits.findOne({id_app:$id_app$$,ma_loai_ts:$ma_loai_ts$$},function($error$$,$v$$){return $error$$||!$v$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 lo\u1ea1i t\u00e0i s\u1ea3n ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
10
- exports.existsNguonvon=[function($id_app$$,$ma_nguon_von$$,$callback$$){$ma_nguon_von$$?Dmnguonvon.findOne({id_app:$id_app$$,ma_nguon_von:$ma_nguon_von$$},function($error$$,$v$$){return $error$$||!$v$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 ngu\u1ed3n v\u1ed1n ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
11
- exports.existsTgts=[function($id_app$$,$ma_tang_giam_ts$$,$callback$$){$ma_tang_giam_ts$$?Dmtanggiamts.findOne({id_app:$id_app$$,ma_tang_giam_ts:$ma_tang_giam_ts$$},function($error$$,$v$$){return $error$$||!$v$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 t\u0103ng gi\u1ea3m t\u00e0i s\u1ea3n ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
1
+ 'use strict';exports.unlockBook=[async function($id_app$$,$ngay_ct$$,$callback$$,$options$$={}){if(!$ngay_ct$$)return $callback$$(!0);global.getModel("app").findOne({_id:$id_app$$},{ngay_ks:1,_id:0},function($error$$,$r$$){if($error$$||!$r$$||$r$$.ngay_ks.getTime()>=$ngay_ct$$.getTime()||$options$$.ngay_ks&&(new Date($options$$.ngay_ks)).getTime()>=$ngay_ct$$.getTime())return $callback$$(!1);$callback$$(!0)})},"\u0110\u00e3 kh\u00f3a s\u1ed5"];
2
+ exports.existsKh=[function($id_app$$,$kh$$,$callback$$){if(!$kh$$)return $callback$$(!0);global.getModel("customer").findOne({id_app:$id_app$$,ma_kh:$kh$$},{ma_kh:1},function($error$$,$cust$$){return $error$$||!$cust$$?$callback$$(!1):$callback$$(!0)})},"M\u00e3 kh\u00e1ch ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
3
+ exports.existsDvcs=[function($id_app$$,$ma_dvcs$$,$callback$$){if(!$ma_dvcs$$)return $callback$$(!0);global.getModel("dvcs").findOne({id_app:$id_app$$,_id:$ma_dvcs$$},function($error$$,$dvcs$$){return $error$$||!$dvcs$$?$callback$$(!1):$callback$$(!0)})},"M\u00e3 \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
4
+ exports.existsNt=[function($id_app$$,$ma_nt$$,$callback$$){$ma_nt$$?global.getModel("currency").findOne({id_app:$id_app$$,ma_nt:$ma_nt$$},function($error$$,$nt$$){return $error$$||!$nt$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 ngo\u1ea1i t\u1ec7 ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
5
+ exports.existsDvt=[function($id_app$$,$ma_dvt$$,$callback$$){$ma_dvt$$?global.getModel("dmdvt").findOne({id_app:$id_app$$,ma_dvt:$ma_dvt$$},function($error$$,$dvt$$){return $error$$||!$dvt$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 \u0111\u01a1n v\u1ecb t\u00ednh ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
6
+ exports.existsVat=[function($id_app$$,$ma_thue$$,$callback$$){$ma_thue$$?global.getModel("vat").findOne({id_app:$id_app$$,ma_thue:$ma_thue$$},function($error$$,$v$$){return $error$$||!$v$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 thu\u1ebf ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
7
+ exports.existsBp=[function($id_app$$,$ma_bp$$,$callback$$){$ma_bp$$?global.getModel("dmbp").findOne({id_app:$id_app$$,ma_bp:$ma_bp$$},function($error$$,$v$$){return $error$$||!$v$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 b\u1ed9 ph\u1eadn ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
8
+ exports.existsLts=[function($id_app$$,$ma_loai_ts$$,$callback$$){$ma_loai_ts$$?global.getModel("dmloaits").findOne({id_app:$id_app$$,ma_loai_ts:$ma_loai_ts$$},function($error$$,$v$$){return $error$$||!$v$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 lo\u1ea1i t\u00e0i s\u1ea3n ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
9
+ exports.existsNguonvon=[function($id_app$$,$ma_nguon_von$$,$callback$$){$ma_nguon_von$$?global.getModel("dmnguonvon").findOne({id_app:$id_app$$,ma_nguon_von:$ma_nguon_von$$},function($error$$,$v$$){return $error$$||!$v$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 ngu\u1ed3n v\u1ed1n ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
10
+ exports.existsTgts=[function($id_app$$,$ma_tang_giam_ts$$,$callback$$){$ma_tang_giam_ts$$?global.getModel("dmtanggiamts").findOne({id_app:$id_app$$,ma_tang_giam_ts:$ma_tang_giam_ts$$},function($error$$,$v$$){return $error$$||!$v$$?$callback$$(!1):$callback$$(!0)}):$callback$$(!0)},"M\u00e3 t\u0103ng gi\u1ea3m t\u00e0i s\u1ea3n ({PATH}) {VALUE} kh\u00f4ng t\u1ed3n t\u1ea1i"];
@@ -1,7 +1,7 @@
1
- 'use strict';const socai=global.getModel("socai"),async=require("async"),underscore=require("underscore"),moment=require("moment");
2
- exports.find=function($query$$,$fn$$,$options$$){async.series({ps_no:function($callback$$){setImmediate(()=>{let $query_no$$={};underscore.extend($query_no$$,$query$$);$query_no$$.tk&&($query_no$$.tk_no=$query_no$$.tk,delete $query_no$$.tk);$query_no$$.ma_kh&&($query_no$$.ma_kh_no=$query_no$$.ma_kh,delete $query_no$$.ma_kh);socai.find($query_no$$).lean().exec(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);async.mapSeries($rs$$,($r$$,$cb$$)=>{setImmediate(()=>{$r$$.tk=$r$$.tk_no;$r$$.tk_du=
3
- $r$$.tk_co;$r$$.ma_kh=$r$$.ma_kh_no;!$r$$.ma_kh&&$r$$.ma_kh_co&&($r$$.ma_kh=$r$$.ma_kh_co);$r$$.ps_no_nt=$r$$.tien_nt;$r$$.ps_no=Math.roundBy($r$$.tien,0);$r$$.ps_co_nt=0;$r$$.ps_co=0;$cb$$()})},()=>{$callback$$(null,$rs$$)})})})},ps_co:function($callback$$){setImmediate(()=>{let $query_co$$={};underscore.extend($query_co$$,$query$$);$query_co$$.tk&&($query_co$$.tk_co=$query_co$$.tk,delete $query_co$$.tk);$query_co$$.ma_kh&&($query_co$$.ma_kh_co=$query_co$$.ma_kh,delete $query_co$$.ma_kh);socai.find($query_co$$).lean().exec(function($e$$,
4
- $rs$$){if($e$$)return $callback$$($e$$);async.mapSeries($rs$$,($r$$,$cb$$)=>{setImmediate(()=>{$r$$.tk=$r$$.tk_co;$r$$.tk_du=$r$$.tk_no;$r$$.ma_kh=$r$$.ma_kh_co;!$r$$.ma_kh&&$r$$.ma_kh_no&&($r$$.ma_kh=$r$$.ma_kh_no);$r$$.ps_co_nt=$r$$.tien_nt;$r$$.ps_co=Math.roundBy($r$$.tien,0);$r$$.ps_no_nt=0;$r$$.ps_no=0;$cb$$()})},()=>{$callback$$(null,$rs$$)})})})}},function($e$jscomp$0$$,$rs$jscomp$0$$){if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);$e$jscomp$0$$=[...$rs$jscomp$0$$.ps_no,...$rs$jscomp$0$$.ps_co];
5
- $options$$&&$options$$.sortData&&($e$jscomp$0$$=$e$jscomp$0$$.sort(($a$$,$b$$)=>{let $a_ngay_ct$$=moment($a$$.ngay_ct).endOf("date").toDate().getTime(),$b_ngay_ct$$=moment($b$$.ngay_ct).endOf("date").toDate().getTime();return $a_ngay_ct$$<$b_ngay_ct$$?-1:$a_ngay_ct$$>$b_ngay_ct$$?1:$a$$.so_ct<$b$$.so_ct?-1:$a$$.so_ct>$b$$.so_ct?1:$a$$.id_ct<$b$$.id_ct?-1:$a$$.id_ct>$b$$.id_ct?1:$a$$.nh_dk<$b$$.nh_dk?-1:$a$$.nh_dk>$b$$.nh_dk||$a$$.ps_no<$b$$.ps_no?1:$a$$.ps_no>$b$$.ps_no||$a$$.ps_co<$b$$.ps_co?-1:
6
- $a$$.ps_co>$b$$.ps_co?1:0}));if($options$$&&$options$$.groupBy){let $groupBy$$;$options$$.groupBy&&(underscore.isArray($options$$.groupBy)&&0<$options$$.groupBy.length&&($groupBy$$=$options$$.groupBy),$groupBy$$=$groupBy$$||"id_app ma_dvcs id_ct ma_ct ma_gd ngay_ct so_ct ngay_hd so_hd tk tk_du ma_kh ong_ba ma_nt ty_gia dien_giai ma_bp id_lenhsx ma_phi ma_hd ma_dt ma_nv ma_sp ma_cp ma_kho ma_vt ma_kenh ma_td1 ma_td2 ma_td3 ma_td4 ma_td5 ma_td6 ma_td7 ma_td8 ma_td9 gio ngay thang quy nam".split(" "));
1
+ 'use strict';const async=require("async"),underscore=require("underscore"),moment=require("moment");
2
+ exports.find=function($query$$,$fn$$,$options$$){const $socai$$=global.getModel("socai");async.series({ps_no:function($callback$$){setImmediate(()=>{let $query_no$$={};underscore.extend($query_no$$,$query$$);$query_no$$.tk&&($query_no$$.tk_no=$query_no$$.tk,delete $query_no$$.tk);$query_no$$.ma_kh&&($query_no$$.ma_kh_no=$query_no$$.ma_kh,delete $query_no$$.ma_kh);$socai$$.find($query_no$$).lean().exec(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);async.mapSeries($rs$$,($r$$,$cb$$)=>{setImmediate(()=>
3
+ {$r$$.tk=$r$$.tk_no;$r$$.tk_du=$r$$.tk_co;$r$$.ma_kh=$r$$.ma_kh_no;!$r$$.ma_kh&&$r$$.ma_kh_co&&($r$$.ma_kh=$r$$.ma_kh_co);$r$$.ps_no_nt=$r$$.tien_nt;$r$$.ps_no=Math.roundBy($r$$.tien,0);$r$$.ps_co_nt=0;$r$$.ps_co=0;$cb$$()})},()=>{$callback$$(null,$rs$$)})})})},ps_co:function($callback$$){setImmediate(()=>{let $query_co$$={};underscore.extend($query_co$$,$query$$);$query_co$$.tk&&($query_co$$.tk_co=$query_co$$.tk,delete $query_co$$.tk);$query_co$$.ma_kh&&($query_co$$.ma_kh_co=$query_co$$.ma_kh,delete $query_co$$.ma_kh);
4
+ $socai$$.find($query_co$$).lean().exec(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);async.mapSeries($rs$$,($r$$,$cb$$)=>{setImmediate(()=>{$r$$.tk=$r$$.tk_co;$r$$.tk_du=$r$$.tk_no;$r$$.ma_kh=$r$$.ma_kh_co;!$r$$.ma_kh&&$r$$.ma_kh_no&&($r$$.ma_kh=$r$$.ma_kh_no);$r$$.ps_co_nt=$r$$.tien_nt;$r$$.ps_co=Math.roundBy($r$$.tien,0);$r$$.ps_no_nt=0;$r$$.ps_no=0;$cb$$()})},()=>{$callback$$(null,$rs$$)})})})}},function($e$jscomp$0$$,$rs$jscomp$0$$){if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);$e$jscomp$0$$=
5
+ [...$rs$jscomp$0$$.ps_no,...$rs$jscomp$0$$.ps_co];$options$$&&$options$$.sortData&&($e$jscomp$0$$=$e$jscomp$0$$.sort(($a$$,$b$$)=>{let $a_ngay_ct$$=moment($a$$.ngay_ct).endOf("date").toDate().getTime(),$b_ngay_ct$$=moment($b$$.ngay_ct).endOf("date").toDate().getTime();return $a_ngay_ct$$<$b_ngay_ct$$?-1:$a_ngay_ct$$>$b_ngay_ct$$?1:$a$$.so_ct<$b$$.so_ct?-1:$a$$.so_ct>$b$$.so_ct?1:$a$$.id_ct<$b$$.id_ct?-1:$a$$.id_ct>$b$$.id_ct?1:$a$$.nh_dk<$b$$.nh_dk?-1:$a$$.nh_dk>$b$$.nh_dk||$a$$.ps_no<$b$$.ps_no?
6
+ 1:$a$$.ps_no>$b$$.ps_no||$a$$.ps_co<$b$$.ps_co?-1:$a$$.ps_co>$b$$.ps_co?1:0}));if($options$$&&$options$$.groupBy){let $groupBy$$;$options$$.groupBy&&(underscore.isArray($options$$.groupBy)&&0<$options$$.groupBy.length&&($groupBy$$=$options$$.groupBy),$groupBy$$=$groupBy$$||"id_app ma_dvcs id_ct ma_ct ma_gd ngay_ct so_ct ngay_hd so_hd tk tk_du ma_kh ong_ba ma_nt ty_gia dien_giai ma_bp id_lenhsx ma_phi ma_hd ma_dt ma_nv ma_sp ma_cp ma_kho ma_vt ma_kenh ma_td1 ma_td2 ma_td3 ma_td4 ma_td5 ma_td6 ma_td7 ma_td8 ma_td9 gio ngay thang quy nam".split(" "));
7
7
  $e$jscomp$0$$.groupBy($groupBy$$,["ps_no","ps_co","ps_no_nt","ps_co_nt"],($e$$,$rs$$)=>{if($e$$)return $fn$$($e$$);$fn$$(null,$rs$$)})}else $fn$$(null,$e$jscomp$0$$)})};