flexbiz-server 12.0.27 → 12.1.1

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.0.27",
5
+ "version": "12.1.1",
6
6
  "author": {
7
7
  "name": "Van Truong Pham",
8
8
  "email": "invncur@gmail.com"
@@ -2,7 +2,7 @@
2
2
  dmqct=global.getModel("dmqct"),counter=global.getModel("counter"),async=require("async"),excel=require("../libs/excel"),permission=require("../libs/permission"),fs=require("fs"),link=global.getModel("link"),Moment=require("moment-timezone"),moment=$time$$=>Moment.tz($time$$,configs.timezone||"Asia/Ho_Chi_Minh"),numeral=require("numeral"),Parameter=global.getModel("parameter"),templatevoucher=global.getModel("templatevoucher"),dvcs=global.getModel("dvcs"),{numberToWord,stripHtmlTags,compileHtml,evalute}=
3
3
  require("../libs/utils"),redisCache=require("../libs/redis-cache"),path=require("path"),htmlReport=require("../libs/htmlReport"),User=global.getModel("user"),Usergroup=global.getModel("usergroup"),textReport=require("../libs/textReport"),dmqddvt=global.getModel("dmqddvt"),StaticPool=require("../libs/WorkerStaticPool"),ERR_NOT_FOUND="ERR_NOT_FOUND: \u0110\u1ed1i t\u01b0\u1ee3ng n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i",ERR_NOT_FOUND_CODE=1100,ERR_NOT_PERMIT="ERR_NOT_PERMIT: Kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n t\u00e1c v\u1ee5 n\u00e0y",
4
4
  ERR_NOT_PERMIT_CODE=1200,ERR_ALREADY_EXIST="ERR_ALREADY_EXIST: \u0110\u1ed1i t\u01b0\u1ee3ng n\u00e0y \u0111\u00e3 th\u1ef1c s\u1ef1 t\u1ed3n t\u1ea1i",ERR_ALREADY_EXIST_CODE=1300,ERR_NOT_HAVE_DATA="ERR_NOT_HAVE_DATA: Kh\u00f4ng c\u00f3 d\u1eef li\u1ec7u",ERR_NOT_HAVE_DATA_CODE=1400,ERR_CAN_NOT_UPDATE="ERR_CAN_NOT_UPDATE: Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",ERR_CAN_NOT_UPDATE_CODE=1500,ERR_DATA_GENERATED="ERR_DATA_GENERATED: \u0110\u00e3 ph\u00e1t sinh d\u1eef li\u1ec7u li\u00ean quan",
5
- ERR_DATA_GENERATED_CODE=1600,ERR_ID_INVALID="ERR_ID_INVALID: Id kh\u00f4ng h\u1ee3p l\u1ec7",ERR_ID_INVALID_CODE=1700,ERR_KEY_ARISE="ERR_KEY_ARISE_DATA: ",ERR_KEY_ARISE_CODE=1800,ERR_ARISE="ERR_ARISE_DATA: ",ERR_ARISE_CODE=1900,ERR_VERIFY_OTP=4001,fields_sync_master_detail=["ma_ct","so_ct","ngay_ct"];function bodyToJson($body$$){$body$$.json&&($body$$=JSON.parse($body$$.json));delete $body$$._id;delete $body$$.__v;return $body$$}
5
+ ERR_DATA_GENERATED_CODE=1600,ERR_ID_INVALID="ERR_ID_INVALID: Id kh\u00f4ng h\u1ee3p l\u1ec7",ERR_ID_INVALID_CODE=1700,ERR_KEY_ARISE="ERR_KEY_ARISE_DATA: ",ERR_KEY_ARISE_CODE=1800,ERR_ARISE="ERR_ARISE_DATA: ",ERR_ARISE_CODE=1900,ERR_VERIFY_OTP=4001,BOOK_LOCK=4444,fields_sync_master_detail=["ma_ct","so_ct","ngay_ct"],validator=require("../libs/validator");function bodyToJson($body$$){$body$$.json&&($body$$=JSON.parse($body$$.json));delete $body$$._id;delete $body$$.__v;return $body$$}
6
6
  async function asyncBodyToJson($body$$,$ctrl$$,$id_app$$,$voucher_options$$){$voucher_options$$||($voucher_options$$=(await OptionsModel.findOne({id_app:$id_app$$,id_func:$ctrl$$.name},{option:1}).lean()||{}).option);$body$$=bodyToJson($body$$);if($voucher_options$$)for(let $field$$ in $voucher_options$$)!$body$$[$field$$]&&"_id"!==$field$$&&$voucher_options$$[$field$$]&&underscore.has($ctrl$$.model.schema.paths,$field$$)&&($body$$[$field$$]=$voucher_options$$[$field$$]);for(let $key$$ in $body$$)if(Array.isArray($body$$[$key$$])&&
7
7
  $body$$[$key$$].forEach($r$$=>{_.isObject($r$$)&&delete $r$$._id}),$body$$[$key$$]&&$body$$[$key$$]instanceof String&&(0==$body$$[$key$$].trim().indexOf("[")||0==$body$$[$key$$].trim().indexOf("{"))&&("mixed"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()||"array"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()))try{$body$$[$key$$]=JSON.parse($body$$[$key$$])}catch($e$$){console.error($e$$)}return $body$$}
8
8
  const getData=($id_app$$,$collection$$,$field$$,$condition$$)=>{if("token"===$collection$$||"asskey"===$collection$$)throw`Collection ${$collection$$} is not allow`;"dmkh"===$collection$$&&($collection$$="customer");"dmtk"===$collection$$&&($collection$$="account");let $col$$=mongoose.models[$collection$$];if($col$$){if($col$$.schema.paths.id_app){if(!$id_app$$)throw`Collection ${$collection$$} required id_app`;$condition$$.id_app=$id_app$$}let $fields$$;$field$$&&($fields$$={[$field$$]:1});if("user"===
@@ -182,13 +182,14 @@ $rs$$)})})})})})})})},pushNotification=controller.pushNotification=($ctrl$$,$_ob
182
182
  0!==$notifications_setting_users_receive_notification$$.length||($notifications_setting_users_receive_notification$$=await Promise.all((($ctrl$$.options||{}).users_receive_notification_default||[]).map($n$$=>new Promise($resolve$$=>{setImmediate(async()=>{underscore.isFunction($n$$)?$resolve$$(await $n$$($obj$jscomp$0$$)):$resolve$$($n$$)})}))));$notifications_setting_users_receive_notification$$&&($notifications_setting_users_receive_notification$$=$notifications_setting_users_receive_notification$$.filter($u$$=>
183
183
  !$u$$.trang_thai||$u$$.trang_thai.toString()===$trang_thai$$||"delete"===$u$$.trang_thai.toString()),$notifications_setting_users_receive_notification$$=$notifications_setting_users_receive_notification$$.filter($func_string$jscomp$1_n$$=>{if(!$func_string$jscomp$1_n$$.condition)return!0;$func_string$jscomp$1_n$$=$func_string$jscomp$1_n$$.condition;0>$func_string$jscomp$1_n$$.indexOf("return ")&&($func_string$jscomp$1_n$$=`return ${$func_string$jscomp$1_n$$}`);try{return evalute($func_string$jscomp$1_n$$,
184
184
  {...$obj$jscomp$0$$,master:$obj$jscomp$0$$,data:$obj$jscomp$0$$})}catch($e$$){return console.error($e$$,$func_string$jscomp$1_n$$),!1}}),$notifications_setting_users_receive_notification$$.forEach(async $p$jscomp$0$$=>{setImmediate(async()=>{let $notificationData$$={_id:$obj$jscomp$0$$._id,trang_thai:$trang_thai$$,id_app:$obj$jscomp$0$$.id_app,code:$obj$jscomp$0$$.ma_ct||$ctrl$$.name,id_link:$obj$jscomp$0$$.id_link,code_link:$obj$jscomp$0$$.code_link,event:$eventName$$,action:$eventName$$.toUpperCase(),
185
- data:$options$$.data};$justFireEvents$$||"delete"===$eventName$$.toLowerCase()?($notificationData$$.title="",$notificationData$$.body=""):($notificationData$$.body=$p$jscomp$0$$.body?compileHtml($p$jscomp$0$$.body,$obj$jscomp$0$$):"",$notificationData$$.title=stripHtmlTags(compileHtml($options$$.title||$p$jscomp$0$$.title||$p$jscomp$0$$.content||"",$obj$jscomp$0$$)));$notificationData$$.title||$notificationData$$.body||($exclude_token$$=null);let $users_will_receive$$=$p$jscomp$0$$.users;$users_will_receive$$||
186
- ($users_will_receive$$=[]);if($p$jscomp$0$$.send_tat_ca_nhan_vien){var $admins_employees_groups_of_user_sandbox$$=(await Usergroup.find({id_app:$obj$jscomp$0$$.id_app,is_employee_group:!0}).lean()).map($g$$=>$g$$._id.toString());0<$admins_employees_groups_of_user_sandbox$$.length&&($admins_employees_groups_of_user_sandbox$$=(await Participant.find({id_app:$obj$jscomp$0$$.id_app,group_id:{$in:$admins_employees_groups_of_user_sandbox$$}}).lean()).map($p$$=>$p$$.email),$users_will_receive$$=$users_will_receive$$.concat($admins_employees_groups_of_user_sandbox$$))}$p$jscomp$0$$.send_phu_trach&&
187
- $obj$jscomp$0$$.phu_trach&&($users_will_receive$$=$users_will_receive$$.concat([$obj$jscomp$0$$.phu_trach]));$p$jscomp$0$$.send_admin&&($admins_employees_groups_of_user_sandbox$$=(await Participant.find({id_app:$obj$jscomp$0$$.id_app,admin:!0}).lean()).map($p$$=>$p$$.email),$users_will_receive$$=$users_will_receive$$.concat($admins_employees_groups_of_user_sandbox$$));$p$jscomp$0$$.send_attends&&$obj$jscomp$0$$.attends&&($users_will_receive$$=$users_will_receive$$.concat($obj$jscomp$0$$.attends));
188
- $p$jscomp$0$$.group_id&&($admins_employees_groups_of_user_sandbox$$=(await Participant.find({id_app:$obj$jscomp$0$$.id_app,group_id:$p$jscomp$0$$.group_id}).lean()).map($u$$=>$u$$.email),$users_will_receive$$=$users_will_receive$$.concat($admins_employees_groups_of_user_sandbox$$));$p$jscomp$0$$.send_to_customer&&($obj$jscomp$0$$.ma_kh||$obj$jscomp$0$$.id_kh)&&($admins_employees_groups_of_user_sandbox$$=await mongoose.models.customer.getInfo($obj$jscomp$0$$.id_app,{$or:[{ma_kh:$obj$jscomp$0$$.ma_kh},
189
- {_id:$obj$jscomp$0$$.id_kh}]},"of_user"))&&($users_will_receive$$=$users_will_receive$$.concat([$admins_employees_groups_of_user_sandbox$$]));$p$jscomp$0$$.send_to_user_created?$users_will_receive$$=$users_will_receive$$.concat([$obj$jscomp$0$$.user_created]):!1===$p$jscomp$0$$.send_to_user_created&&($users_will_receive$$=$users_will_receive$$.filter($u$$=>$u$$!==$obj$jscomp$0$$.user_created));if($p$jscomp$0$$.handle_receivers){$admins_employees_groups_of_user_sandbox$$={obj:$obj$jscomp$0$$,users_will_receive:$users_will_receive$$};
190
- try{let $str_func$$=$p$jscomp$0$$.handle_receivers;0!==$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);0>$str_func$$.indexOf("async ")&&($users_will_receive$$=evalute($str_func$$,$admins_employees_groups_of_user_sandbox$$))}catch($e$$){console.error($e$$)}}$ctrl$$.options||($ctrl$$.options={});$ctrl$$.options.onEmitEvent||($ctrl$$.options.onEmitEvent=($obj$$,$users_will_receive$$,$next$$,$_notificationData$$)=>{$next$$(null,$users_will_receive$$,$_notificationData$$)});$ctrl$$.options.onEmitEvent(Object.assign({},
191
- $obj$jscomp$0$$),$users_will_receive$$,($e$$,$_users_will_receive$$,$_notificationData$$)=>{setImmediate(()=>{if($e$$)return console.error("Error emit events",$e$$);$_users_will_receive$$=underscore.uniq($_users_will_receive$$);0<$_users_will_receive$$.length&&app.emitEvent($obj$jscomp$0$$.id_app,`${$ctrl$$.name.toLowerCase()}:${$eventName$$}`,$_notificationData$$||$notificationData$$,$exclude_token$$,$_users_will_receive$$,!0)})},Object.assign({},$notificationData$$),Object.assign({},$p$jscomp$0$$))})}))})})}})};
185
+ data:$options$$.data};$justFireEvents$$||"delete"===$eventName$$.toLowerCase()?($notificationData$$.title="",$notificationData$$.body=""):($notificationData$$.body=$p$jscomp$0$$.body?compileHtml($p$jscomp$0$$.body,$obj$jscomp$0$$):"",$notificationData$$.title=stripHtmlTags(compileHtml($options$$.title||$p$jscomp$0$$.title||$p$jscomp$0$$.content||"",$obj$jscomp$0$$)));$p$jscomp$0$$.email_content&&($p$jscomp$0$$.email_content=compileHtml($p$jscomp$0$$.email_content,$obj$jscomp$0$$));$notificationData$$.title||
186
+ $notificationData$$.body||($exclude_token$$=null);let $users_will_receive$$=$p$jscomp$0$$.users;$users_will_receive$$||($users_will_receive$$=[]);if($p$jscomp$0$$.send_tat_ca_nhan_vien){var $admins_employees_groups_of_user_sandbox$$=(await Usergroup.find({id_app:$obj$jscomp$0$$.id_app,is_employee_group:!0}).lean()).map($g$$=>$g$$._id.toString());0<$admins_employees_groups_of_user_sandbox$$.length&&($admins_employees_groups_of_user_sandbox$$=(await Participant.find({id_app:$obj$jscomp$0$$.id_app,group_id:{$in:$admins_employees_groups_of_user_sandbox$$}}).lean()).map($p$$=>
187
+ $p$$.email),$users_will_receive$$=$users_will_receive$$.concat($admins_employees_groups_of_user_sandbox$$))}$p$jscomp$0$$.send_phu_trach&&$obj$jscomp$0$$.phu_trach&&($users_will_receive$$=$users_will_receive$$.concat([$obj$jscomp$0$$.phu_trach]));$p$jscomp$0$$.send_admin&&($admins_employees_groups_of_user_sandbox$$=(await Participant.find({id_app:$obj$jscomp$0$$.id_app,admin:!0}).lean()).map($p$$=>$p$$.email),$users_will_receive$$=$users_will_receive$$.concat($admins_employees_groups_of_user_sandbox$$));
188
+ $p$jscomp$0$$.send_attends&&$obj$jscomp$0$$.attends&&($users_will_receive$$=$users_will_receive$$.concat($obj$jscomp$0$$.attends));$p$jscomp$0$$.group_id&&($admins_employees_groups_of_user_sandbox$$=(await Participant.find({id_app:$obj$jscomp$0$$.id_app,group_id:$p$jscomp$0$$.group_id}).lean()).map($u$$=>$u$$.email),$users_will_receive$$=$users_will_receive$$.concat($admins_employees_groups_of_user_sandbox$$));$p$jscomp$0$$.send_to_customer&&($obj$jscomp$0$$.ma_kh||$obj$jscomp$0$$.id_kh)&&($admins_employees_groups_of_user_sandbox$$=
189
+ await mongoose.models.customer.getInfo($obj$jscomp$0$$.id_app,{$or:[{ma_kh:$obj$jscomp$0$$.ma_kh},{_id:$obj$jscomp$0$$.id_kh}]},"of_user"))&&($users_will_receive$$=$users_will_receive$$.concat([$admins_employees_groups_of_user_sandbox$$]));$p$jscomp$0$$.send_to_user_created?$users_will_receive$$=$users_will_receive$$.concat([$obj$jscomp$0$$.user_created]):!1===$p$jscomp$0$$.send_to_user_created&&($users_will_receive$$=$users_will_receive$$.filter($u$$=>$u$$!==$obj$jscomp$0$$.user_created));if($p$jscomp$0$$.handle_receivers){$admins_employees_groups_of_user_sandbox$$=
190
+ {obj:$obj$jscomp$0$$,users_will_receive:$users_will_receive$$};try{let $str_func$$=$p$jscomp$0$$.handle_receivers;0!==$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);0>$str_func$$.indexOf("async ")&&($users_will_receive$$=evalute($str_func$$,$admins_employees_groups_of_user_sandbox$$))}catch($e$$){console.error($e$$)}}$ctrl$$.options||($ctrl$$.options={});$ctrl$$.options.onEmitEvent||($ctrl$$.options.onEmitEvent=($obj$$,$users_will_receive$$,$next$$,$_notificationData$$)=>{$next$$(null,
191
+ $users_will_receive$$,$_notificationData$$)});$ctrl$$.options.onEmitEvent(Object.assign({},$obj$jscomp$0$$),$users_will_receive$$,($e$$,$_users_will_receive$$,$_notificationData$$)=>{setImmediate(()=>{if($e$$)return console.error("Error emit events",$e$$);$_users_will_receive$$=underscore.uniq($_users_will_receive$$);0<$_users_will_receive$$.length&&app.emitEvent($obj$jscomp$0$$.id_app,`${$ctrl$$.name.toLowerCase()}:${$eventName$$}`,$_notificationData$$||$notificationData$$,$exclude_token$$,$_users_will_receive$$,
192
+ !0)})},Object.assign({},$notificationData$$),Object.assign({},$p$jscomp$0$$))})}))})})}})};
192
193
  async function createIdRef($model$$,$data$$){$model$$=Object.values($model$$.schema.paths).filter($path$$=>$path$$.options&&$path$$.options.ref&&$path$$.options.localField&&$path$$.options.foreignField);try{return await Promise.all($model$$.map($path$$=>new Promise($resove$$=>{setImmediate(async()=>{let $namePath$$=$path$$.path;var $modelRef_modelRefName$$=$path$$.options.ref,$localField_obj$$=$path$$.options.localField;let $foreignField$$=$path$$.options.foreignField;$data$$[$localField_obj$$]?($modelRef_modelRefName$$=
193
194
  mongoose.models[$modelRef_modelRefName$$.toLowerCase()])?($localField_obj$$=await $modelRef_modelRefName$$.findOne({id_app:$data$$.id_app,[$foreignField$$]:$data$$[$localField_obj$$]}).lean(),$data$$[$namePath$$]=$localField_obj$$?$localField_obj$$._id.toString():null):$data$$[$namePath$$]=null:$data$$[$namePath$$]=null;$resove$$($path$$)})})))}catch($e2$$){return console.error("error create ref data",$e2$$),null}}
194
195
  async function create($user$jscomp$0$$,$ctrl$$,$data$$,$callback$jscomp$1$$,$id_be_supply_by_user$$,$req$$){try{const $model$$=$ctrl$$.model,$voucher_options$$=(await OptionsModel.findOne({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name}).lean()||{}).option,$schema_paths$$=$model$$.schema.paths;let $v_data$$;try{$v_data$$=await asyncBodyToJson($data$$,$ctrl$$,$user$jscomp$0$$.current_id_app,$voucher_options$$)}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}underscore.has($schema_paths$$,
@@ -230,47 +231,48 @@ null,$req$$)};this.router.route(`${this.route_name}/quickcreate/:template_code`)
230
231
  const update=async function($user$jscomp$0$$,$ctrl$$,$id$$,$data$jscomp$0$$,$callback$jscomp$1$$,$action$jscomp$0$$,$req$$){delete $data$jscomp$0$$.__v;try{const $model$$=$ctrl$$.model,$unique$$=$ctrl$$.unique,$module$$=$ctrl$$.module,$schema_paths$$=$model$$.schema.paths;underscore.has($schema_paths$$,"ma_ct")&&$ctrl$$.options.isVoucher&&($data$jscomp$0$$.ma_ct=$ctrl$$.name.toUpperCase());delete $data$jscomp$0$$.session_updated;delete $data$jscomp$0$$.session_created;$req$$&&$req$$.cookies&&underscore.has($schema_paths$$,
231
232
  "session_updated")&&($data$jscomp$0$$.session_updated=$req$$.req.cookies.uid);const $voucher_options$$=(await OptionsModel.findOne({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name}).lean()||{}).option;let $current_obj$$;if($ctrl$$.options.requireRecaptchaToken){if(!$data$jscomp$0$$["g-recaptcha-response"])return $callback$jscomp$1$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u g-recaptcha-response");try{await permission.verifyReCaptcha($data$jscomp$0$$["g-recaptcha-response"])}catch($e$$){return $callback$jscomp$1$$($e$$.message||
232
233
  $e$$.error||$e$$)}}if(0>global.configs.admins.indexOf($user$jscomp$0$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($data$jscomp$0$$,{action:"update",_id:$id$$,user:$user$jscomp$0$$}));if($requireOtp$$)try{await permission.verifyOTP($user$jscomp$0$$.email,$data$jscomp$0$$["otp-id"],$data$jscomp$0$$["otp-code"])}catch($e$$){return $callback$jscomp$1$$({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}async.waterfall([function($callback$$){setImmediate(function(){$model$$.findOne({_id:$id$$}).exec(function($error$$,
233
- $obj$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);if(!$obj$$)return $callback$$("Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y");underscore.has($schema_paths$$,"exfields")&&($obj$$.exfields=$obj$$.exfields||{});const $old_obj$$=$obj$$.toObject();$current_obj$$=_.cloneDeep($old_obj$$);const $data_keys$$=Object.keys($data$jscomp$0$$);for(let $key$$ in $old_obj$$)0>$data_keys$$.indexOf($key$$)&&($data$jscomp$0$$[$key$$]=$old_obj$$[$key$$]);$callback$$(null,
234
- $obj$$)})})})},function($obj$$,$callback$$){setImmediate(function(){permission.hasRight($user$jscomp$0$$.current_id_app,$user$jscomp$0$$.email,$module$$,"update",function($error$$,$hr$$,$c_app$$){setImmediate(()=>{if($hr$$)$ctrl$$.checkData($c_app$$,{...$data$jscomp$0$$,_id:$obj$$._id.toString()},$e$$=>{if($e$$)return $callback$$($e$$);$callback$$(null,$obj$$)});else return $callback$$({error:$error$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})})},{data:$data$jscomp$0$$,obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})},
235
- function($obj$$,$callback$$){underscore.has($model$$.schema.paths,"ngay_ct")&&underscore.has($model$$.schema.paths,"so_ct")&&$obj$$.ngay_ct&&$data$jscomp$0$$.so_ct&&$obj$$.so_ct!==$data$jscomp$0$$.so_ct?OptionsModel.findOne({id_app:$obj$$.id_app,id_func:$ctrl$$.name},{option:1}).lean().exec(($e$jscomp$0$$,$rs$jscomp$0$$)=>{setImmediate(()=>{if($rs$jscomp$0$$&&$rs$jscomp$0$$.option&&$rs$jscomp$0$$.option.check_so_ct&&"0"!==$rs$jscomp$0$$.option.check_so_ct){let $query_check$$={id_app:$obj$$.id_app,
236
- so_ct:$data$jscomp$0$$.so_ct,_id:{$ne:$obj$$._id.toString()}},$tu_ngay$$;var $date_check_den_ngay$$=$data$jscomp$0$$.ngay_ct||$obj$$.ngay_ct;switch($rs$jscomp$0$$.option.check_so_ct){case "1":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("date").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("date").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "2":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("month").toDate();$date_check_den_ngay$$=
237
- moment($date_check_den_ngay$$).endOf("month").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "3":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("quarter").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("quarter").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "8":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$date_check_den_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),
238
- $query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($rs$$)return $callback$$("S\u1ed1 ch\u1ee9ng t\u1eeb "+$data$jscomp$0$$.so_ct+" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c");$callback$$(null,$obj$$)})})}else $callback$$(null,$obj$$)})}):$callback$$(null,$obj$$)},($obj$jscomp$0$$,$callback$jscomp$0$$)=>{(async($obj$$,$callback$$)=>{try{(await permission.getFieldNotRight($obj$$.id_app,
239
- $user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $data$jscomp$0$$[$f$$]})}catch($e$$){console.error("Error get field not right",$e$$)}setImmediate(function(){$ctrl$$.updating?$ctrl$$.updating($user$jscomp$0$$,$data$jscomp$0$$,$obj$$,function($error$jscomp$0$$,$_data$jscomp$0$$,$_obj$$){setImmediate(()=>{if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);if($ctrl$$.dynamicUpdating)$ctrl$$.dynamicUpdating($user$jscomp$0$$,$_data$jscomp$0$$,$_obj$$,function($error$$,$_data$$){if($error$$)return $callback$$($error$$);
240
- for(let $f$$ in $_data$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$$[$f$$]);$callback$$(null,$obj$$)});else{for(let $f$$ in $_data$jscomp$0$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$jscomp$0$$[$f$$]);$callback$$(null,$obj$$)}})}):$ctrl$$.dynamicUpdating?$ctrl$$.dynamicUpdating($req$$.user,$data$jscomp$0$$,$obj$$,function($error$$,$_data$$){if($error$$)return $callback$$($error$$);for(let $f$$ in $_data$$)underscore.has($schema_paths$$,$f$$)&&
241
- ($data$jscomp$0$$[$f$$]=$_data$$[$f$$]);$callback$$(null,$obj$$)}):$callback$$(null,$obj$$)})})($obj$jscomp$0$$,$callback$jscomp$0$$)},function($obj$$,$callback$$){setImmediate(function(){if(!$unique$$||0===$unique$$.length)return $callback$$(null,$obj$$);let $c1$$={},$c2$$={};$obj$$.id_app&&($c1$$.id_app=$obj$$.id_app,$c2$$.id_app||($c2$$.id_app=$obj$$.id_app));$unique$$.forEach(function($key$$){$c1$$[$key$$]=$obj$$[$key$$];$ctrl$$.model.schema.paths[$key$$]?("number"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?
242
- $c2$$[$key$$]=Number($data$jscomp$0$$[$key$$]):"date"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=new Date($data$jscomp$0$$[$key$$]):"string"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=($data$jscomp$0$$[$key$$]||"").toString():$c2$$[$key$$]=$data$jscomp$0$$[$key$$],$c2$$[$key$$]||($c2$$[$key$$]=$c1$$[$key$$])):console.error("field",$key$$," is not exist. please check unique of controller")});!0!==underscore.isEqual($c1$$,$c2$$)?isExists($model$$,
243
- $unique$$,$c2$$,$ctrl$$.replaceIfExists,function($error$jscomp$0$$,$kq$$){setImmediate(()=>{if($error$jscomp$0$$||$kq$$){let $msgError$$=$error$jscomp$0$$||ERR_ALREADY_EXIST;console.error($msgError$$,$c2$$);if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}else checkReference($model$$,$obj$$,function($error$$){setImmediate(()=>{if($error$$)return console.error("Keys arise data",
244
- $c1$$,$c2$$,$error$$),$callback$$({error:ERR_KEY_ARISE+($error$$.error||$error$$.message||$error$$),code:ERR_KEY_ARISE_CODE});$callback$$(null,$obj$$)})},$unique$$)})}):$callback$$(null,$obj$$)})},function($obj$$,$callback$$){let $keys$$=underscore.keys($model$$.referenceKeys).filter($key$$=>"_id"!==$key$$);$unique$$&&($keys$$=$keys$$.filter($key$$=>0>$unique$$.indexOf($key$$).length));if(0===$keys$$.length)return $callback$$(null,$obj$$);checkReference($model$$,$obj$$,function($msgError$$){setImmediate(()=>
245
- {if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$({error:ERR_ARISE+($msgError$$.error||$msgError$$.message||$msgError$$),code:ERR_ARISE_CODE});else $callback$$(null,$obj$$)})},$keys$$)},function($obj$jscomp$1$$,$callback$$){$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,
246
- $obj$jscomp$1$$,($error$$,$obj$jscomp$0$$)=>{if($error$$)return $callback$$($error$$);setImmediate(function(){$data$jscomp$0$$.date_updated=new Date;$data$jscomp$0$$.user_updated=$user$jscomp$0$$.email;delete $data$jscomp$0$$.__v;$ctrl$$.options.onUpdateExtending||($ctrl$$.options.onUpdateExtending=function($obj$$,$data$$,$action$$,$fn$$){$fn$$()});$ctrl$$.options.onUpdateExtending($obj$jscomp$0$$,$data$jscomp$0$$,$action$jscomp$0$$,function(){underscore.has($schema_paths$$,"exfields")&&$data$jscomp$0$$.exfields&&
247
- ($obj$jscomp$0$$.exfields=$data$jscomp$0$$.exfields);delete $data$jscomp$0$$.__v;for(let $f$$ in $data$jscomp$0$$)underscore.has($schema_paths$$,$f$$)&&"_id"!==$f$$&&($obj$jscomp$0$$.set($f$$,$data$jscomp$0$$[$f$$]),"exfields"!==$f$$||$obj$jscomp$0$$.exfields||($obj$jscomp$0$$.exfields={}));validate($obj$jscomp$0$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+
248
- "\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$);else $callback$$(null,$obj$jscomp$0$$)})})})})})},function($obj$$,$callback$$){$current_obj$$&&($obj$$._id=$current_obj$$._id);deletePost($user$jscomp$0$$,$obj$$,async $e$$=>{$callback$$($e$$,$obj$$)})},function($obj$$,$callback$$){setImmediate(async()=>{$obj$$.ngay_ct&&($obj$$.ngay_ct=moment($obj$$.ngay_ct).toDate());for(var $$condition_k$$ in $ctrl$$.keyValues)$obj$$[$$condition_k$$]=$ctrl$$.keyValues[$$condition_k$$];
249
- Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$$[$model_path$$]&&underscore.isArray($obj$$[$model_path$$])).forEach($model_path$$=>{$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>"line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&0<=fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$$[$path$$]&&$obj$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>
250
- {$detail$$[$path$$]=$obj$$[$path$$]})})});await createIdRef($model$$,$obj$$);$ctrl$$.saving&&await $ctrl$$.saving($user$jscomp$0$$,$obj$$);$ctrl$$.emit("saving",$obj$$);$current_obj$$&&($obj$$._id=$current_obj$$._id);let $obj_created$$,$error$jscomp$0$$;$data$jscomp$0$$.$condition&&($$condition_k$$=$data$jscomp$0$$.$condition,$$condition_k$$._id=$obj$$._id,await $model$$.findOne($$condition_k$$)||($error$jscomp$0$$=ERR_CAN_NOT_UPDATE),delete $data$jscomp$0$$.$condition);if(!$error$jscomp$0$$)try{delete $obj$$.__v,
251
- $obj_created$$=await $obj$$.save()}catch($e$$){$error$jscomp$0$$=$e$$}if($error$jscomp$0$$){let $msgErrors$$=[];for(let $k$$ in $error$jscomp$0$$.errors)$msgErrors$$.push($error$jscomp$0$$.errors[$k$$].message);0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&console.error("onErrorUpdating",$e$$);$callback$$({error:$msgErrors$$,
252
- code:ERR_CAN_NOT_UPDATE_CODE})},$current_obj$$);else $callback$$({error:$msgErrors$$,code:ERR_CAN_NOT_UPDATE_CODE})}else $req$$&&$req$$.header&&setImmediate(()=>{log.create({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name,action:"UPDATE",data:{oldData:$current_obj$$,newData:$data$jscomp$0$$,id:$obj$$._id.toString()}},$user$jscomp$0$$.email,$req$$.header("user-agent"),$req$$)}),postData($obj_created$$,$ctrl$$,function($msgError$$){$msgError$$?setImmediate(()=>{$current_obj$$&&$model$$.findByIdAndUpdate($current_obj$$._id,
253
- {$set:$current_obj$$},function($err$$,$restore_data$$){if($err$$||!$restore_data$$)return console.error("can't restore voucher",$err$$||": don't find voucher");console.log("restored data of voucher. posting...");$model$$.findById($current_obj$$._id,($e$jscomp$0$$,$_d$$)=>{if(!$_d$$)return console.error("Don't find voucher",$current_obj$$._id);postData($_d$$,$ctrl$$,function($e$$){if($e$$)return console.error("can't repost voucher",$e$$);console.log("reposted voucher",$_d$$._id)})})});if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,
234
+ $obj$$){setImmediate(async()=>{if($error$$)return $callback$$($error$$);if(!$obj$$)return $callback$$("Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y");if($obj$$.ngay_ct&&$obj$$.id_app&&$obj$$.schema&&$obj$$.schema.validate&&$obj$$.schema.validate.ngay_ct)try{await new Promise(($rs$$,$rj$$)=>{validator.unlockBook[0]($obj$$.id_app,$obj$$.ngay_ct,$unlock$$=>{if(!$unlock$$)return $rj$$(validator.unlockBook[1]);$rs$$($unlock$$)})})}catch($e$$){return $callback$$($e$$.message||
235
+ $e$$.error||$e$$)}underscore.has($schema_paths$$,"exfields")&&($obj$$.exfields=$obj$$.exfields||{});const $old_obj$$=$obj$$.toObject();$current_obj$$=_.cloneDeep($old_obj$$);const $data_keys$$=Object.keys($data$jscomp$0$$);for(let $key$$ in $old_obj$$)0>$data_keys$$.indexOf($key$$)&&($data$jscomp$0$$[$key$$]=$old_obj$$[$key$$]);$callback$$(null,$obj$$)})})})},function($obj$$,$callback$$){setImmediate(function(){permission.hasRight($user$jscomp$0$$.current_id_app,$user$jscomp$0$$.email,$module$$,"update",
236
+ function($error$$,$hr$$,$c_app$$){setImmediate(()=>{if($hr$$)$ctrl$$.checkData($c_app$$,{...$data$jscomp$0$$,_id:$obj$$._id.toString()},$e$$=>{if($e$$)return $callback$$($e$$);$callback$$(null,$obj$$)});else return $callback$$({error:$error$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})})},{data:$data$jscomp$0$$,obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})},function($obj$$,$callback$$){underscore.has($model$$.schema.paths,"ngay_ct")&&underscore.has($model$$.schema.paths,"so_ct")&&$obj$$.ngay_ct&&
237
+ $data$jscomp$0$$.so_ct&&$obj$$.so_ct!==$data$jscomp$0$$.so_ct?OptionsModel.findOne({id_app:$obj$$.id_app,id_func:$ctrl$$.name},{option:1}).lean().exec(($e$jscomp$0$$,$rs$jscomp$0$$)=>{setImmediate(()=>{if($rs$jscomp$0$$&&$rs$jscomp$0$$.option&&$rs$jscomp$0$$.option.check_so_ct&&"0"!==$rs$jscomp$0$$.option.check_so_ct){let $query_check$$={id_app:$obj$$.id_app,so_ct:$data$jscomp$0$$.so_ct,_id:{$ne:$obj$$._id.toString()}},$tu_ngay$$;var $date_check_den_ngay$$=$data$jscomp$0$$.ngay_ct||$obj$$.ngay_ct;
238
+ switch($rs$jscomp$0$$.option.check_so_ct){case "1":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("date").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("date").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "2":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("month").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("month").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "3":$tu_ngay$$=
239
+ moment($date_check_den_ngay$$).startOf("quarter").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("quarter").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "8":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$date_check_den_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().exec(($e$$,$rs$$)=>
240
+ {setImmediate(()=>{if($rs$$)return $callback$$("S\u1ed1 ch\u1ee9ng t\u1eeb "+$data$jscomp$0$$.so_ct+" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c");$callback$$(null,$obj$$)})})}else $callback$$(null,$obj$$)})}):$callback$$(null,$obj$$)},($obj$jscomp$0$$,$callback$jscomp$0$$)=>{(async($obj$$,$callback$$)=>{try{(await permission.getFieldNotRight($obj$$.id_app,$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $data$jscomp$0$$[$f$$]})}catch($e$$){console.error("Error get field not right",
241
+ $e$$)}setImmediate(function(){$ctrl$$.updating?$ctrl$$.updating($user$jscomp$0$$,$data$jscomp$0$$,$obj$$,function($error$jscomp$0$$,$_data$jscomp$0$$,$_obj$$){setImmediate(()=>{if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);if($ctrl$$.dynamicUpdating)$ctrl$$.dynamicUpdating($user$jscomp$0$$,$_data$jscomp$0$$,$_obj$$,function($error$$,$_data$$){if($error$$)return $callback$$($error$$);for(let $f$$ in $_data$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$$[$f$$]);
242
+ $callback$$(null,$obj$$)});else{for(let $f$$ in $_data$jscomp$0$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$jscomp$0$$[$f$$]);$callback$$(null,$obj$$)}})}):$ctrl$$.dynamicUpdating?$ctrl$$.dynamicUpdating($req$$.user,$data$jscomp$0$$,$obj$$,function($error$$,$_data$$){if($error$$)return $callback$$($error$$);for(let $f$$ in $_data$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$$[$f$$]);$callback$$(null,$obj$$)}):$callback$$(null,$obj$$)})})($obj$jscomp$0$$,
243
+ $callback$jscomp$0$$)},function($obj$$,$callback$$){setImmediate(function(){if(!$unique$$||0===$unique$$.length)return $callback$$(null,$obj$$);let $c1$$={},$c2$$={};$obj$$.id_app&&($c1$$.id_app=$obj$$.id_app,$c2$$.id_app||($c2$$.id_app=$obj$$.id_app));$unique$$.forEach(function($key$$){$c1$$[$key$$]=$obj$$[$key$$];$ctrl$$.model.schema.paths[$key$$]?("number"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=Number($data$jscomp$0$$[$key$$]):"date"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?
244
+ $c2$$[$key$$]=new Date($data$jscomp$0$$[$key$$]):"string"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=($data$jscomp$0$$[$key$$]||"").toString():$c2$$[$key$$]=$data$jscomp$0$$[$key$$],$c2$$[$key$$]||($c2$$[$key$$]=$c1$$[$key$$])):console.error("field",$key$$," is not exist. please check unique of controller")});!0!==underscore.isEqual($c1$$,$c2$$)?isExists($model$$,$unique$$,$c2$$,$ctrl$$.replaceIfExists,function($error$jscomp$0$$,$kq$$){setImmediate(()=>{if($error$jscomp$0$$||
245
+ $kq$$){let $msgError$$=$error$jscomp$0$$||ERR_ALREADY_EXIST;console.error($msgError$$,$c2$$);if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}else checkReference($model$$,$obj$$,function($error$$){setImmediate(()=>{if($error$$)return console.error("Keys arise data",$c1$$,$c2$$,$error$$),$callback$$({error:ERR_KEY_ARISE+($error$$.error||
246
+ $error$$.message||$error$$),code:ERR_KEY_ARISE_CODE});$callback$$(null,$obj$$)})},$unique$$)})}):$callback$$(null,$obj$$)})},function($obj$$,$callback$$){let $keys$$=underscore.keys($model$$.referenceKeys).filter($key$$=>"_id"!==$key$$);$unique$$&&($keys$$=$keys$$.filter($key$$=>0>$unique$$.indexOf($key$$).length));if(0===$keys$$.length)return $callback$$(null,$obj$$);checkReference($model$$,$obj$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,
247
+ $obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$({error:ERR_ARISE+($msgError$$.error||$msgError$$.message||$msgError$$),code:ERR_ARISE_CODE});else $callback$$(null,$obj$$)})},$keys$$)},function($obj$jscomp$1$$,$callback$$){$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,$obj$jscomp$1$$,($error$$,$obj$jscomp$0$$)=>{if($error$$)return $callback$$($error$$);
248
+ setImmediate(function(){$data$jscomp$0$$.date_updated=new Date;$data$jscomp$0$$.user_updated=$user$jscomp$0$$.email;delete $data$jscomp$0$$.__v;$ctrl$$.options.onUpdateExtending||($ctrl$$.options.onUpdateExtending=function($obj$$,$data$$,$action$$,$fn$$){$fn$$()});$ctrl$$.options.onUpdateExtending($obj$jscomp$0$$,$data$jscomp$0$$,$action$jscomp$0$$,function(){underscore.has($schema_paths$$,"exfields")&&$data$jscomp$0$$.exfields&&($obj$jscomp$0$$.exfields=$data$jscomp$0$$.exfields);delete $data$jscomp$0$$.__v;
249
+ for(let $f$$ in $data$jscomp$0$$)underscore.has($schema_paths$$,$f$$)&&"_id"!==$f$$&&($obj$jscomp$0$$.set($f$$,$data$jscomp$0$$[$f$$]),"exfields"!==$f$$||$obj$jscomp$0$$.exfields||($obj$jscomp$0$$.exfields={}));validate($obj$jscomp$0$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$);
250
+ else $callback$$(null,$obj$jscomp$0$$)})})})})})},function($obj$$,$callback$$){$current_obj$$&&($obj$$._id=$current_obj$$._id);deletePost($user$jscomp$0$$,$obj$$,async $e$$=>{$callback$$($e$$,$obj$$)})},function($obj$$,$callback$$){setImmediate(async()=>{$obj$$.ngay_ct&&($obj$$.ngay_ct=moment($obj$$.ngay_ct).toDate());for(var $$condition_k$$ in $ctrl$$.keyValues)$obj$$[$$condition_k$$]=$ctrl$$.keyValues[$$condition_k$$];Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$$[$model_path$$]&&
251
+ underscore.isArray($obj$$[$model_path$$])).forEach($model_path$$=>{$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>"line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&0<=fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$$[$path$$]&&$obj$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>{$detail$$[$path$$]=$obj$$[$path$$]})})});await createIdRef($model$$,
252
+ $obj$$);$ctrl$$.saving&&await $ctrl$$.saving($user$jscomp$0$$,$obj$$);$ctrl$$.emit("saving",$obj$$);$current_obj$$&&($obj$$._id=$current_obj$$._id);let $obj_created$$,$error$jscomp$0$$;$data$jscomp$0$$.$condition&&($$condition_k$$=$data$jscomp$0$$.$condition,$$condition_k$$._id=$obj$$._id,await $model$$.findOne($$condition_k$$)||($error$jscomp$0$$=ERR_CAN_NOT_UPDATE),delete $data$jscomp$0$$.$condition);if(!$error$jscomp$0$$)try{delete $obj$$.__v,$obj_created$$=await $obj$$.save()}catch($e$$){$error$jscomp$0$$=
253
+ $e$$}if($error$jscomp$0$$){let $msgErrors$$=[];for(let $k$$ in $error$jscomp$0$$.errors)$msgErrors$$.push($error$jscomp$0$$.errors[$k$$].message);0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&console.error("onErrorUpdating",$e$$);$callback$$({error:$msgErrors$$,code:ERR_CAN_NOT_UPDATE_CODE})},$current_obj$$);else $callback$$({error:$msgErrors$$,
254
+ code:ERR_CAN_NOT_UPDATE_CODE})}else $req$$&&$req$$.header&&setImmediate(()=>{log.create({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name,action:"UPDATE",data:{oldData:$current_obj$$,newData:$data$jscomp$0$$,id:$obj$$._id.toString()}},$user$jscomp$0$$.email,$req$$.header("user-agent"),$req$$)}),postData($obj_created$$,$ctrl$$,function($msgError$$){$msgError$$?setImmediate(()=>{$current_obj$$&&$model$$.findByIdAndUpdate($current_obj$$._id,{$set:$current_obj$$},function($err$$,$restore_data$$){if($err$$||
255
+ !$restore_data$$)return console.error("can't restore voucher",$err$$||": don't find voucher");console.log("restored data of voucher. posting...");$model$$.findById($current_obj$$._id,($e$jscomp$0$$,$_d$$)=>{if(!$_d$$)return console.error("Don't find voucher",$current_obj$$._id);postData($_d$$,$ctrl$$,function($e$$){if($e$$)return console.error("can't repost voucher",$e$$);console.log("reposted voucher",$_d$$._id)})})});if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,
254
256
  $obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}):setImmediate(()=>{$ctrl$$.emit("saved",$obj_created$$);$ctrl$$.emit("updated",$obj_created$$);$obj_created$$=$obj_created$$.toObject();runWebhooks($ctrl$$,$obj_created$$,"UPDATE",$voucher_options$$);$ctrl$$.cacheData($obj_created$$);if($req$$&&!1!==$req$$.query.return_data)$ctrl$$.onView($user$jscomp$0$$,[$obj_created$$],function($error$$,$viewValue$$){setImmediate(()=>
255
257
  {if($error$$)return $callback$$($error$$);$req$$&&pushNotification($ctrl$$,$viewValue$$[0],"update",$current_obj$$,null,{exclude_token:$req$$.query.access_token});$callback$$(null,$viewValue$$[0])})},{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id})})})})},function($obj$$,$callback$$){$ctrl$$.requestApprove($user$jscomp$0$$.current_app_info,$user$jscomp$0$$,$obj$$,$callback$$,$voucher_options$$)},function($obj$jscomp$0$$,$callback$$){void 0!=$obj$jscomp$0$$.trang_thai&&setImmediate(async()=>
256
258
  {Approve.findOne({id_ct:$obj$jscomp$0$$._id.toString(),"update_after_approve.data.trang_thai":$obj$jscomp$0$$.trang_thai.toString()}).lean().exec(($e$$,$rs$$)=>{!$rs$$||$rs$$.user_approved||$rs$$.user_denied||($rs$$.user_approved=$req$$.user.email,$rs$$.user_approved_name=$req$$.user.name,$rs$$.date_approved=new Date,Approve.updateOne({_id:$rs$$._id},$rs$$).then(()=>{Approve.sendNotifyApproved($rs$$,$req$$.query.access_token)}))})});setImmediate(async()=>{(await permission.getFieldNotRight($obj$jscomp$0$$.id_app,
257
259
  $user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $obj$jscomp$0$$[$f$$]});$obj$jscomp$0$$.collection_name=$ctrl$$.collection_name;$ctrl$$.updated?$ctrl$$.updated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$jscomp$0$$,$obj$$){if($error$jscomp$0$$)return console.error("error when saved",$error$jscomp$0$$),$callback$$($error$jscomp$0$$);$ctrl$$.dynamicUpdated?$ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)}):
258
- $callback$$(null,$obj$$)},$current_obj$$):$ctrl$$.dynamicUpdated?$ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$jscomp$0$$)}):$callback$$(null,$obj$jscomp$0$$)})}],($e$jscomp$165_name_cached$$,$rs$$)=>{$e$jscomp$165_name_cached$$?(console.error($e$jscomp$165_name_cached$$),$callback$jscomp$1$$($e$jscomp$165_name_cached$$)):($e$jscomp$165_name_cached$$=$model$$.collection.name,$user$jscomp$0$$.current_id_app&&
259
- ($e$jscomp$165_name_cached$$+=$user$jscomp$0$$.current_id_app),delete global.cacheDatas[$e$jscomp$165_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),$callback$jscomp$1$$($e$$)}};
260
+ $callback$$(null,$obj$$)},$current_obj$$):$ctrl$$.dynamicUpdated?$ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$jscomp$0$$)}):$callback$$(null,$obj$jscomp$0$$)})}],($e$jscomp$166_name_cached$$,$rs$$)=>{$e$jscomp$166_name_cached$$?(console.error($e$jscomp$166_name_cached$$),$callback$jscomp$1$$($e$jscomp$166_name_cached$$)):($e$jscomp$166_name_cached$$=$model$$.collection.name,$user$jscomp$0$$.current_id_app&&
261
+ ($e$jscomp$166_name_cached$$+=$user$jscomp$0$$.current_id_app),delete global.cacheDatas[$e$jscomp$166_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),$callback$jscomp$1$$($e$$)}};
260
262
  controller.prototype.update=function(){let $ctrl$$=this,$name$$=this.name;this.router.route(this.route_name+"/:id").put(function($req$$,$res$$){let $session$$=$req$$.session;if(!0===$session$$["updating_"+$name$$])return $res$$.status(400).send({error:"\u0110ang x\u1eed l\u00fd d\u1eef li\u1ec7u"});$session$$["updating_"+$name$$]=!0;let $body$$=$req$$.body;$req$$.files&&underscore.extend($body$$,$req$$.files);let $data$$;try{$data$$=bodyToJson($body$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||
261
263
  $e$$.error||$e$$})}update($req$$.user,$ctrl$$,$req$$.params.id,$data$$,($e$$,$rs$$)=>{setImmediate(()=>{$session$$["updating_"+$name$$]=!1;if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});!1===$req$$.query.return_data?$res$$.send({_id:$rs$$._id.toString()}):$res$$.send($rs$$)})},null,$req$$)})};
262
264
  function checkReference($model$jscomp$0$$,$obj$$,$fn$$,$keys$$){$model$jscomp$0$$.referenceKeys?($keys$$||($keys$$=underscore.keys($model$jscomp$0$$.referenceKeys)),async.map($keys$$,function($key$$,$callback$$){setImmediate(()=>{let $ref$$=$model$jscomp$0$$.referenceKeys[$key$$];if(!$ref$$)return $callback$$();let $value$$=$obj$$[$key$$];"_id"===$key$$&&($value$$=$value$$.toString());if(void 0==$value$$||null==$value$$||""==$value$$)return $callback$$();async.map($ref$$,function($r$$,$cb$$){setImmediate(()=>
263
265
  {let $model$$=mongoose.models[$r$$.model];if($model$$){let $query$$={id_app:$obj$$.id_app};var $_w_k$$=$r$$.key;$_w_k$$&&($query$$[$_w_k$$]=$value$$);$r$$.where&&(underscore.isObject($r$$.where)&&($query$$=Object.assign($query$$,$r$$.where)),underscore.isFunction($r$$.where)&&($_w_k$$=$r$$.where($obj$$),$query$$=Object.assign($query$$,$_w_k$$)));$model$$.find($query$$).limit(1).lean().exec(function($error$$,$o$$){setImmediate(()=>{if($error$$)return $cb$$($error$$);if($o$$&&0<$o$$.length){let $msgError$$;
264
266
  $msgError$$=$r$$.error?(new Function("obj","return `"+$r$$.error.replace("{{VALUE}}",$value$$)+"`"))($obj$$):ERR_DATA_GENERATED;return $cb$$({error:$msgError$$,code:ERR_DATA_GENERATED_CODE})}$cb$$()})})}else $cb$$()})},function($e$$){if($e$$)return $callback$$($e$$);$callback$$()})})},$error$$=>{$fn$$($error$$)})):$fn$$()}
265
- controller.prototype.delete=function(){let $model$$=this.model,$ctrl$$=this,$module$$=this.module;this.router.route(this.route_name+"/:id").delete(function($req$$,$res$$,$next$$){if(!global.mongoose.Types.ObjectId.isValid($req$$.params.id))return $res$$.status(400).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$model$$.findOne({_id:$req$$.params.id}).lean().exec(async function($e$jscomp$170_user$$,$obj$$){if($e$jscomp$170_user$$)return console.error($e$jscomp$170_user$$),$e$jscomp$170_user$$.error?
266
- $res$$.status(400).send($e$jscomp$170_user$$):$res$$.status(400).send({error:$e$jscomp$170_user$$.message||$e$jscomp$170_user$$.error||$e$jscomp$170_user$$});if(!$obj$$)return $res$$.status(404).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$e$jscomp$170_user$$=$req$$.user;if(0>global.configs.admins.indexOf($e$jscomp$170_user$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($obj$$,{action:"delete",_id:$req$$.params.id,
267
- user:$e$jscomp$170_user$$}));if($requireOtp$$)try{await permission.verifyOTP($e$jscomp$170_user$$.email,$req$$.query["otp-id"],$req$$.query["otp-code"])}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}setImmediate(()=>{permission.hasRight($obj$$.id_app,$req$$.user.email,$module$$,"delete",function($error$jscomp$0$$,$hr$$){if($hr$$)checkReference($model$$,$obj$$,function($error$$){if($error$$)return $res$$.status(400).send({error:ERR_ARISE+($error$$.error||
268
- $error$$.message||$error$$),code:ERR_ARISE_CODE});$req$$.obj=$obj$$;$next$$()});else return $res$$.status(403).send({error:$error$jscomp$0$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})},{obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})})},function($req$$,$res$$,$next$$){setImmediate(()=>{let $obj$jscomp$1$$=$req$$.obj;$ctrl$$.deleting?$ctrl$$.deleting($req$$.user,$obj$jscomp$1$$,function($e$$,$obj$jscomp$0$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||
269
- $e$$});$ctrl$$.dynamicDeleting?$ctrl$$.dynamicDeleting($req$$.user,$obj$jscomp$0$$,function($error$$,$obj$$){if($error$$)return $next$$($error$$);$req$$.obj=$obj$$;$next$$()}):($req$$.obj=$obj$jscomp$0$$,$next$$())},{req:$req$$}):$ctrl$$.dynamicDeleting?$ctrl$$.dynamicDeleting($req$$.user,$obj$jscomp$1$$,function($error$$,$obj$$){if($error$$)return $next$$($error$$);$req$$.obj=$obj$$;$next$$()}):($req$$.obj=$obj$jscomp$1$$,$next$$())})},function($req$$,$res$$){setImmediate(()=>{let $obj$jscomp$0$$=
270
- $req$$.obj;$ctrl$$.emit("deleting",{...$obj$jscomp$0$$});deletePost($req$$.user,$obj$jscomp$0$$,async $e$jscomp$1$$=>{if($e$jscomp$1$$)return console.error($e$jscomp$1$$),$e$jscomp$1$$.error?$res$$.status(400).send($e$jscomp$1$$):$res$$.status(400).send({error:$e$jscomp$1$$.message||$e$jscomp$1$$});if($ctrl$$.dynamicDeletePost)try{await $ctrl$$.dynamicDeletePost($obj$jscomp$0$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$})}$model$$.deleteOne({_id:$obj$jscomp$0$$._id},
271
- function($e$jscomp$0$$){if($e$jscomp$0$$)return console.error($e$jscomp$0$$),$e$jscomp$0$$.error?$res$$.status(400).send($e$jscomp$0$$):$res$$.status(400).send({error:$e$jscomp$0$$.message||$e$jscomp$0$$});setImmediate(()=>{$ctrl$$.deleteData({...$obj$jscomp$0$$});log.create({id_app:$req$$.user.current_id_app,id_func:$ctrl$$.name,action:"DELETE",data:{id:$obj$jscomp$0$$._id,data:$obj$jscomp$0$$}},$req$$.user.email,$req$$.header("user-agent"),$req$$);link.deleteMany({$or:[{id_a:$obj$jscomp$0$$._id},
272
- {id_b:$obj$jscomp$0$$._id}]},function($e$$){$e$$&&console.error("Can't delete links\n"+$e$$)})});setImmediate(()=>{$ctrl$$.emit("deleted",$obj$jscomp$0$$);runWebhooks($ctrl$$,$obj$jscomp$0$$,"DELETE")});pushNotification($ctrl$$,$obj$jscomp$0$$,"delete",null,null,{exclude_token:$req$$.query.access_token});setImmediate(()=>{$ctrl$$.deleted?$ctrl$$.deleted($req$$.user,$obj$jscomp$0$$,function($e$$,$obj$$){setImmediate(()=>{if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||
273
- $e$$});$res$$.send($obj$$)})}):$res$$.send($obj$jscomp$0$$)})})})})})};
267
+ controller.prototype.delete=function(){let $model$$=this.model,$ctrl$$=this,$module$$=this.module;this.router.route(this.route_name+"/:id").delete(function($req$$,$res$$,$next$$){if(!global.mongoose.Types.ObjectId.isValid($req$$.params.id))return $res$$.status(400).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$model$$.findOne({_id:$req$$.params.id}).exec(async function($e$jscomp$171_user$$,$obj$$){if($e$jscomp$171_user$$)return console.error($e$jscomp$171_user$$),$e$jscomp$171_user$$.error?
268
+ $res$$.status(400).send($e$jscomp$171_user$$):$res$$.status(400).send({error:$e$jscomp$171_user$$.message||$e$jscomp$171_user$$.error||$e$jscomp$171_user$$});if(!$obj$$)return $res$$.status(404).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});if($obj$$.ngay_ct&&$obj$$.id_app&&$obj$$.schema&&$obj$$.schema.validate&&$obj$$.schema.validate.ngay_ct)try{await new Promise(($rs$$,$rj$$)=>{validator.unlockBook[0]($obj$$.id_app,$obj$$.ngay_ct,$unlock$$=>{if(!$unlock$$)return $rj$$(validator.unlockBook[1]);
269
+ $rs$$($unlock$$)})})}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$,code:BOOK_LOCK})}$obj$$=$obj$$.toObject();$e$jscomp$171_user$$=$req$$.user;if(0>global.configs.admins.indexOf($e$jscomp$171_user$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($obj$$,{action:"delete",_id:$req$$.params.id,user:$e$jscomp$171_user$$}));if($requireOtp$$)try{await permission.verifyOTP($e$jscomp$171_user$$.email,
270
+ $req$$.query["otp-id"],$req$$.query["otp-code"])}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}setImmediate(()=>{permission.hasRight($obj$$.id_app,$req$$.user.email,$module$$,"delete",function($error$jscomp$0$$,$hr$$){if($hr$$)checkReference($model$$,$obj$$,function($error$$){if($error$$)return $res$$.status(400).send({error:ERR_ARISE+($error$$.error||$error$$.message||$error$$),code:ERR_ARISE_CODE});$req$$.obj=$obj$$;$next$$()});else return $res$$.status(403).send({error:$error$jscomp$0$$||
271
+ ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})},{obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})})},function($req$$,$res$$,$next$$){setImmediate(()=>{let $obj$jscomp$1$$=$req$$.obj;$ctrl$$.deleting?$ctrl$$.deleting($req$$.user,$obj$jscomp$1$$,function($e$$,$obj$jscomp$0$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$ctrl$$.dynamicDeleting?$ctrl$$.dynamicDeleting($req$$.user,$obj$jscomp$0$$,function($error$$,$obj$$){if($error$$)return $next$$($error$$);
272
+ $req$$.obj=$obj$$;$next$$()}):($req$$.obj=$obj$jscomp$0$$,$next$$())},{req:$req$$}):$ctrl$$.dynamicDeleting?$ctrl$$.dynamicDeleting($req$$.user,$obj$jscomp$1$$,function($error$$,$obj$$){if($error$$)return $next$$($error$$);$req$$.obj=$obj$$;$next$$()}):($req$$.obj=$obj$jscomp$1$$,$next$$())})},function($req$$,$res$$){setImmediate(()=>{let $obj$jscomp$0$$=$req$$.obj;$ctrl$$.emit("deleting",{...$obj$jscomp$0$$});deletePost($req$$.user,$obj$jscomp$0$$,async $e$jscomp$1$$=>{if($e$jscomp$1$$)return console.error($e$jscomp$1$$),
273
+ $e$jscomp$1$$.error?$res$$.status(400).send($e$jscomp$1$$):$res$$.status(400).send({error:$e$jscomp$1$$.message||$e$jscomp$1$$});if($ctrl$$.dynamicDeletePost)try{await $ctrl$$.dynamicDeletePost($obj$jscomp$0$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$})}$model$$.deleteOne({_id:$obj$jscomp$0$$._id},function($e$jscomp$0$$){if($e$jscomp$0$$)return console.error($e$jscomp$0$$),$e$jscomp$0$$.error?$res$$.status(400).send($e$jscomp$0$$):$res$$.status(400).send({error:$e$jscomp$0$$.message||
274
+ $e$jscomp$0$$});setImmediate(()=>{$ctrl$$.deleteData({...$obj$jscomp$0$$});log.create({id_app:$req$$.user.current_id_app,id_func:$ctrl$$.name,action:"DELETE",data:{id:$obj$jscomp$0$$._id,data:$obj$jscomp$0$$}},$req$$.user.email,$req$$.header("user-agent"),$req$$);link.deleteMany({$or:[{id_a:$obj$jscomp$0$$._id},{id_b:$obj$jscomp$0$$._id}]},function($e$$){$e$$&&console.error("Can't delete links\n"+$e$$)})});setImmediate(()=>{$ctrl$$.emit("deleted",$obj$jscomp$0$$);runWebhooks($ctrl$$,$obj$jscomp$0$$,
275
+ "DELETE")});pushNotification($ctrl$$,$obj$jscomp$0$$,"delete",null,null,{exclude_token:$req$$.query.access_token});setImmediate(()=>{$ctrl$$.deleted?$ctrl$$.deleted($req$$.user,$obj$jscomp$0$$,function($e$$,$obj$$){setImmediate(()=>{if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($obj$$)})}):$res$$.send($obj$jscomp$0$$)})})})})})};
274
276
  controller.prototype.history=function(){let $name$$=this.name;this.router.route(this.route_name+"/g/history/:id").get(function($actions_req$$,$res$$){let $query$$={id_func:$name$$,id_app:$actions_req$$.user.current_id_app,"data.id":$actions_req$$.params.id};($actions_req$$=$actions_req$$.query.actions)?($actions_req$$=$actions_req$$.split(","),$query$$.action={$in:$actions_req$$,$ne:"GET"}):$query$$.action={$ne:"GET"};log.find($query$$).lean().exec(function($e$$,$rs$$){setImmediate(()=>$e$$?(console.error($e$$),
275
277
  $e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})):$res$$.send($rs$$))})})};
276
278
  controller.prototype.logs=function(){let $ctrl$$=this,$name$$=this.name;this.router.route(this.route_name+"/g/log/:action").get(function($req$$,$res$$){var $action$jscomp$3_den_ngay$$=$req$$.params.action.toUpperCase();let $query$$={id_func:$name$$,id_app:$req$$.user.current_id_app};"ALL"!==$action$jscomp$3_den_ngay$$&&($query$$.action=$action$jscomp$3_den_ngay$$);if($req$$.query.tu_ngay){var $date_created_tu_ngay$$=moment(new Date($req$$.query.tu_ngay)).startOf("date").toDate();$date_created_tu_ngay$$=
@@ -26,11 +26,11 @@ $url$$),$reject$$($e$$))})})},ping=async $from_address$$=>{console.log("ping fro
26
26
  $u$$&&User.emitEvent($u$$.user_created,"blockchain.wallet.changed",{receiver:$receiver$$,data:$data$$})});[...(new Set($owners$$))].filter($o$$=>!$senders$$.find($s$$=>$s$$==$o$$)).filter($o$$=>!$receivers$$.find($s$$=>$s$$==$o$$)).forEach(async $owner$$=>{let $u$$=await getKeyByAddress($owner$$);$u$$&&User.emitEvent($u$$.user_created,"blockchain.wallet.changed",{receiver:$owner$$,sender:$owner$$,data:$data$$})})}catch($e$$){console.error("error emit events",$e$$.message)}};let notificationPool={};
27
27
  const processEventAt=async $events$$=>{let $receivers$$=[];for(let $key$$ in $events$$)$events$$[$key$$].forEach(async $action$$=>{(0<=$key$$.indexOf(".receiver")||0<=$key$$.indexOf(".recipient")||0<=$key$$.indexOf(".sender")||0<=$key$$.indexOf(".creator")||0<=$key$$.indexOf(".owner")||0<=$key$$.indexOf(".buyer")||0<=$key$$.indexOf(".seller"))&&$receivers$$.push($action$$)});[...(new Set($receivers$$))].forEach(async $receiver$$=>{let $u$$=await getKeyByAddress($receiver$$);$u$$&&$events$$["at.action"].forEach(async($_u_action$$,
28
28
  $id$jscomp$2_index$jscomp$17_title_token$$)=>{let $creator$$=$events$$["at.creator"]&&$events$$["at.creator"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.creator"][$id$jscomp$2_index$jscomp$17_title_token$$]:"",$owner$$=$events$$["at.owner"]&&$events$$["at.owner"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.owner"][$id$jscomp$2_index$jscomp$17_title_token$$]:"",$memo$$=$events$$["at.memo"]&&$events$$["at.memo"].length>$id$jscomp$2_index$jscomp$17_title_token$$?
29
- $events$$["at.memo"][$id$jscomp$2_index$jscomp$17_title_token$$]:"";if(!(0<=$memo$$.toLowerCase().indexOf("n\u1ea1p ti\u1ec1n"))){var $timestamp$$=$events$$["at.timestamp"]&&$events$$["at.timestamp"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.timestamp"][$id$jscomp$2_index$jscomp$17_title_token$$]:"";$timestamp$$=Number($timestamp$$||0)+$id$jscomp$2_index$jscomp$17_title_token$$;switch($_u_action$$){case "send":$_u_action$$=$events$$["at.sender"]&&$events$$["at.sender"].length>
30
- $id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.sender"][$id$jscomp$2_index$jscomp$17_title_token$$]:"";if($receiver$$!==$_u_action$$){var $id_invest_noti_sender$jscomp$1_token$$="";$_u_action$$&&($_u_action$$=await getKeyByAddress($_u_action$$))&&($id_invest_noti_sender$jscomp$1_token$$=$_u_action$$.name);$_u_action$$=$events$$["at.denom"]&&$events$$["at.denom"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.denom"][$id$jscomp$2_index$jscomp$17_title_token$$]:"vnd";$id$jscomp$2_index$jscomp$17_title_token$$=
31
- `${$id_invest_noti_sender$jscomp$1_token$$||"unknow"} \u0111\u00e3 g\u1eedi cho b\u1ea1n ${numeral($events$$["at.amount"]&&$events$$["at.amount"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.amount"][$id$jscomp$2_index$jscomp$17_title_token$$]:0).format()} ${$_u_action$$}`;$id_invest_noti_sender$jscomp$1_token$$={title:$id$jscomp$2_index$jscomp$17_title_token$$,receiver:$receiver$$,body:`${$id$jscomp$2_index$jscomp$17_title_token$$} v\u1edbi n\u1ed9i dung: ${$memo$$}`,data:{key:"send:"+
32
- $timestamp$$}}}break;case "withdraw":$id$jscomp$2_index$jscomp$17_title_token$$=$events$$["at.idWithdraw"]&&$events$$["at.idWithdraw"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.idWithdraw"][$id$jscomp$2_index$jscomp$17_title_token$$]:"";$id_invest_noti_sender$jscomp$1_token$$={title:"X\u1eed l\u00fd r\u00fat v\u1ed1n",receiver:$receiver$$,body:$memo$$||`Y\u00eau c\u1ea7u r\u00fat v\u1ed1n s\u1ed1 ${$id$jscomp$2_index$jscomp$17_title_token$$} \u0111\u00e3 \u0111\u01b0\u1ee3c x\u1eed l\u00fd xong`,
33
- data:{key:"withdraw:"+$id$jscomp$2_index$jscomp$17_title_token$$+$timestamp$$,id_withdraw:$events$$["at.idWithdraw"]}};break;case "buy":$receiver$$===$creator$$&&($id_invest_noti_sender$jscomp$1_token$$={title:"Mua th\u00e0nh c\u00f4ng",receiver:$receiver$$,body:$memo$$||`B\u1ea1n \u0111\u00e3 mua th\u00e0nh c\u00f4ng ${$events$$["at.amount"][$id$jscomp$2_index$jscomp$17_title_token$$]} ${$events$$["at.token"][$id$jscomp$2_index$jscomp$17_title_token$$]}`,data:{key:`buy:${$events$$["at.idNeedToBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]}-${$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$]}`+
29
+ $events$$["at.memo"][$id$jscomp$2_index$jscomp$17_title_token$$]:"",$timestamp$$=$events$$["at.timestamp"]&&$events$$["at.timestamp"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.timestamp"][$id$jscomp$2_index$jscomp$17_title_token$$]:"";$timestamp$$=Number($timestamp$$||0)+$id$jscomp$2_index$jscomp$17_title_token$$;switch($_u_action$$){case "send":$_u_action$$=$events$$["at.sender"]&&$events$$["at.sender"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.sender"][$id$jscomp$2_index$jscomp$17_title_token$$]:
30
+ "";if($receiver$$!==$_u_action$$){var $id_invest_noti_sender$jscomp$1_token$$="";$_u_action$$&&($_u_action$$=await getKeyByAddress($_u_action$$))&&($id_invest_noti_sender$jscomp$1_token$$=$_u_action$$.name);$_u_action$$=$events$$["at.denom"]&&$events$$["at.denom"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.denom"][$id$jscomp$2_index$jscomp$17_title_token$$]:"vnd";$id$jscomp$2_index$jscomp$17_title_token$$=`${$id_invest_noti_sender$jscomp$1_token$$||"unknow"} \u0111\u00e3 g\u1eedi cho b\u1ea1n ${numeral($events$$["at.amount"]&&
31
+ $events$$["at.amount"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.amount"][$id$jscomp$2_index$jscomp$17_title_token$$]:0).format()} ${$_u_action$$}`;$id_invest_noti_sender$jscomp$1_token$$={title:$id$jscomp$2_index$jscomp$17_title_token$$,receiver:$receiver$$,body:`${$id$jscomp$2_index$jscomp$17_title_token$$} v\u1edbi n\u1ed9i dung: ${$memo$$}`,create_notify:0>$memo$$.toLowerCase().indexOf("n\u1ea1p ti\u1ec1n"),data:{key:"send:"+$timestamp$$}}}break;case "withdraw":$id$jscomp$2_index$jscomp$17_title_token$$=
32
+ $events$$["at.idWithdraw"]&&$events$$["at.idWithdraw"].length>$id$jscomp$2_index$jscomp$17_title_token$$?$events$$["at.idWithdraw"][$id$jscomp$2_index$jscomp$17_title_token$$]:"";$id_invest_noti_sender$jscomp$1_token$$={title:"X\u1eed l\u00fd r\u00fat v\u1ed1n",receiver:$receiver$$,body:$memo$$||`Y\u00eau c\u1ea7u r\u00fat v\u1ed1n s\u1ed1 ${$id$jscomp$2_index$jscomp$17_title_token$$} \u0111\u00e3 \u0111\u01b0\u1ee3c x\u1eed l\u00fd xong`,data:{key:"withdraw:"+$id$jscomp$2_index$jscomp$17_title_token$$+
33
+ $timestamp$$,id_withdraw:$events$$["at.idWithdraw"]}};break;case "buy":$receiver$$===$creator$$&&($id_invest_noti_sender$jscomp$1_token$$={title:"Mua th\u00e0nh c\u00f4ng",receiver:$receiver$$,body:$memo$$||`B\u1ea1n \u0111\u00e3 mua th\u00e0nh c\u00f4ng ${$events$$["at.amount"][$id$jscomp$2_index$jscomp$17_title_token$$]} ${$events$$["at.token"][$id$jscomp$2_index$jscomp$17_title_token$$]}`,data:{key:`buy:${$events$$["at.idNeedToBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]}-${$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$]}`+
34
34
  $timestamp$$,id_need_to_buy:$events$$["at.idNeedToBuy"][$id$jscomp$2_index$jscomp$17_title_token$$],id_sell:$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$]}});break;case "sell":$receiver$$===$creator$$&&($id_invest_noti_sender$jscomp$1_token$$={title:"B\u00e1n th\u00e0nh c\u00f4ng",receiver:$receiver$$,body:$memo$$||`B\u1ea1n \u0111\u00e3 b\u00e1n th\u00e0nh c\u00f4ng ${$events$$["at.amount"][$id$jscomp$2_index$jscomp$17_title_token$$]} ${$events$$["at.token"][$id$jscomp$2_index$jscomp$17_title_token$$]}`,
35
35
  data:{key:`sell:${$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$]}-${$events$$["at.idBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]}`+$timestamp$$,id_sell:$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$],id_buy:$events$$["at.idBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]}});break;case "sell-expired":if($receiver$$===$creator$$){let $id_sell$$=$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$];global.getModel("asssell").updateOne({id:$id_sell$$},
36
36
  {trang_thai:"9"}).then($rs$$=>{console.log("updated expired asssell",$id_sell$$,$rs$$)});$id_invest_noti_sender$jscomp$1_token$$={title:"Tin b\u00e1n h\u1ebft h\u1ea1n",receiver:$receiver$$,body:$memo$$||`Tin b\u00e1n s\u1ed1 ${$id_sell$$} \u0111\u00e3 h\u1ebft h\u1ea1n. Token \u0111\u00e3 \u0111\u01b0\u1ee3c chuy\u1ec3n l\u1ea1i v\u00e0o v\u00ed c\u1ee7a b\u1ea1n`,data:{key:"sell-expired:"+$id_sell$$+$timestamp$$,id_sell:$id_sell$$}}}break;case "need-to-buy-expired":if($receiver$$===$creator$$){let $id_need_to_buy$$=
@@ -43,9 +43,9 @@ id_profit_sharing:$events$$["at.idProfitSharing"][$id$jscomp$2_index$jscomp$17_t
43
43
  $token$$=$events$$["at.token"][$id$jscomp$2_index$jscomp$17_title_token$$];global.getModel("assinvestment").updateOne({id:$id_invest$$},{trang_thai:"5"}).then($rs$$=>{console.log("updated expired assinvestment",$id_invest$$,$rs$$)});$token$$&&global.getModel("asssell").updateOne({token:$token$$},{trang_thai:"5"}).then($rs$$=>{console.log("updated expired asssell for token",$token$$,$rs$$)});$id_invest_noti_sender$jscomp$1_token$$={title:"Kho\u1ea3n \u0111\u1ea7u t\u01b0 \u0111\u00e1o h\u1ea1n",receiver:$receiver$$,
44
44
  body:$memo$$||`Kho\u1ea3n \u0111\u1ea7u t\u01b0 ${$token$$} \u0111\u00e3 \u0111\u00e1o h\u1ea1n. Ti\u1ec1n g\u1ed1c v\u00e0 l\u00e3i \u0111\u00e3 \u0111\u01b0\u1ee3c chuy\u1ec3n v\u00e0o v\u00ed c\u1ee7a b\u1ea1n`,data:{key:"invest-expired:"+$id_invest$$+$timestamp$$,id_invest:$id_invest$$,token:$token$$}}}break;case "exchange":$id_invest_noti_sender$jscomp$1_token$$={title:"Giao d\u1ecbch c\u1ee7a b\u1ea1n \u0111\u00e3 kh\u1edbp l\u1ec7nh",receiver:$receiver$$,body:$memo$$||`\u0110\u00e3 kh\u1edbp l\u1ec7nh giao d\u1ecbch gi\u1eefa tin mua s\u1ed1 ${$events$$["at.idNeedToBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]} v\u00e0 tin b\u00e1n s\u1ed1 ${$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$]}. V\u00ed c\u1ee7a b\u1ea1n \u0111\u00e3 \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt s\u1ed1 d\u01b0`,
45
45
  data:{key:`exchange:${$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$]}-${$events$$["at.idNeedToBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]}`+$timestamp$$,id_sell:$events$$["at.idSell"][$id$jscomp$2_index$jscomp$17_title_token$$],id_need_to_buy:$events$$["at.idNeedToBuy"][$id$jscomp$2_index$jscomp$17_title_token$$]}};break;default:console.log("don't implement action",$_u_action$$)}$id_invest_noti_sender$jscomp$1_token$$&&($id_invest_noti_sender$jscomp$1_token$$.user=$u$$.user_created,
46
- $id_invest_noti_sender$jscomp$1_token$$.data.key=$id_invest_noti_sender$jscomp$1_token$$.user+$id_invest_noti_sender$jscomp$1_token$$.data.key,notificationPool[$id_invest_noti_sender$jscomp$1_token$$.data.key]=$id_invest_noti_sender$jscomp$1_token$$)}})})},WS=require("ws");let notiInterval,connectSocket=!1;
46
+ $id_invest_noti_sender$jscomp$1_token$$.data.key=$id_invest_noti_sender$jscomp$1_token$$.user+$id_invest_noti_sender$jscomp$1_token$$.data.key,notificationPool[$id_invest_noti_sender$jscomp$1_token$$.data.key]=$id_invest_noti_sender$jscomp$1_token$$)})})},WS=require("ws");let notiInterval,connectSocket=!1;
47
47
  const setupSocket=()=>{if(!connectSocket){var $ws$$=new WS(configs.BLOCKCHAIN_SOCKET);$ws$$.on("error",$e$$=>{connectSocket=!1;console.error("Can't connect to blockchain socket server",$e$$.message);notiInterval&&(clearInterval(notiInterval),notiInterval=null)});$ws$$.on("close",()=>{connectSocket=!1;notiInterval&&(clearInterval(notiInterval),notiInterval=null);setTimeout(()=>{setupSocket()},5E3)});$ws$$.on("open",()=>{console.log("connected to blockchain socket");connectSocket=!0;$ws$$.send(JSON.stringify({jsonrpc:"2.0",
48
- method:"subscribe",id:"0",params:{query:"tm.event = 'Tx'"}}));$ws$$.send(JSON.stringify({jsonrpc:"2.0",method:"subscribe",id:"1",params:{query:"at.event = 'auto'"}}));notiInterval=setInterval(()=>{const $values$$=Object.values(notificationPool);notificationPool={};0<$values$$.length&&console.log("create notifications",$values$$);$values$$.forEach($noti$$=>{User.emitEvent($noti$$.user,"blockchain.wallet.changed",{receiver:$noti$$.receiver,data:$noti$$.data});global.createNotification("SYSTEM",$noti$$.user,
49
- $noti$$.title,$noti$$.body,$e$$=>{$e$$&&console.error($e$$.message)},$noti$$.data,!0)})},3E3)});$ws$$.on("message",async $data$jscomp$8_msg$$=>{($data$jscomp$8_msg$$=JSON.parse($data$jscomp$8_msg$$))&&$data$jscomp$8_msg$$.result&&$data$jscomp$8_msg$$.result.events&&($data$jscomp$8_msg$$.result.events["at.event"]&&$data$jscomp$8_msg$$.result.events["at.action"]&&processEventAt($data$jscomp$8_msg$$.result.events,$data$jscomp$8_msg$$),$data$jscomp$8_msg$$.result.events["tx.hash"]&&0<$data$jscomp$8_msg$$.result.events["tx.hash"].length&&
48
+ method:"subscribe",id:"0",params:{query:"tm.event = 'Tx'"}}));$ws$$.send(JSON.stringify({jsonrpc:"2.0",method:"subscribe",id:"1",params:{query:"at.event = 'auto'"}}));notiInterval=setInterval(()=>{const $values$$=Object.values(notificationPool);notificationPool={};0<$values$$.length&&console.log("create notifications",$values$$);$values$$.forEach($noti$$=>{User.emitEvent($noti$$.user,"blockchain.wallet.changed",{receiver:$noti$$.receiver,data:$noti$$.data});0!=$noti$$.create_notify&&global.createNotification("SYSTEM",
49
+ $noti$$.user,$noti$$.title,$noti$$.body,$e$$=>{$e$$&&console.error($e$$.message)},$noti$$.data,!0)})},3E3)});$ws$$.on("message",async $data$jscomp$8_msg$$=>{($data$jscomp$8_msg$$=JSON.parse($data$jscomp$8_msg$$))&&$data$jscomp$8_msg$$.result&&$data$jscomp$8_msg$$.result.events&&($data$jscomp$8_msg$$.result.events["at.event"]&&$data$jscomp$8_msg$$.result.events["at.action"]&&processEventAt($data$jscomp$8_msg$$.result.events,$data$jscomp$8_msg$$),$data$jscomp$8_msg$$.result.events["tx.hash"]&&0<$data$jscomp$8_msg$$.result.events["tx.hash"].length&&
50
50
  processEventTx($data$jscomp$8_msg$$))})}},initSocket=()=>{configs.BLOCKCHAIN_SOCKET&&setTimeout(()=>{global.configs.cluster?global.clientRedis.get("lastworker",($e$jscomp$0$$,$lastworker$$)=>{if($lastworker$$){try{$lastworker$$=JSON.parse($lastworker$$)}catch($e$$){console.error($e$$);return}process.pid!=$lastworker$$.pid||$lastworker$$.initSocket||($lastworker$$.initSocket=!0,global.clientRedis.set("lastworker",JSON.stringify($lastworker$$)),console.log("init socket connect to blockchain on worker",
51
51
  $lastworker$$),setupSocket())}}):setupSocket()},1E3*(global.configs.cluster?60:1))};module.exports={getAccount,getWallet,getKeyByAddress,getKeyInfo,ping,connectWithSigner,getClient,bankBalancesGet,getPrice,spend,createTx,getTxStatus,txQuery,bcQuery,tdQuery,initSocket,getLatestHash,getHashById,findHash,mining};
@@ -15,12 +15,12 @@ $e_key_right$$=$email$$;$participant$$&&$participant$$.group_id&&($e_key_right$$
15
15
  ma_trang_thai:$options$$.obj.trang_thai},function($e$$,$trang_thai$$){if($e$$)return $callback$$($e$$);if($trang_thai$$){if("update"===$action$$){if(0==$trang_thai$$.allow_update)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p s\u1eeda");if(1==$trang_thai$$.lock_data)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c kho\u00e1")}if("delete"===$action$$&&($trang_thai$$.lock_data||0==$trang_thai$$.allow_delete))return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p xo\u00e1")}return $callback$$()}):
16
16
  $callback$$()}},$e$$=>{$e$$?$callback$jscomp$0$$($e$$,!1):$callback$jscomp$0$$(null,!0,$app$$)}):$callback$jscomp$0$$(null,!0,$app$$)})},$options$$)};
17
17
  exports.getRightByItem=function($id_app$$,$model$$,$email$$,$next$$,$module$$,$options$$={}){exports.isAdmin($id_app$$,$email$$,async function($e$jscomp$3_key_right$$,$admin$$,$app$$,$participant$$){if($e$jscomp$3_key_right$$)return $next$$($e$jscomp$3_key_right$$);let $condition$$={};$module$$||($module$$=$model$$&&$model$$.collection&&$model$$.collection.name&&1<$model$$.collection.name.length?$model$$.collection.name.substr(0,$model$$.collection.name.length-1).toLowerCase():"");if($admin$$||$options$$.notNeedRight)$next$$(null,
18
- $condition$$,$admin$$);else{const $ds_dang_phu_trach$$=await exports.dsDangPhuTrach($id_app$$,$email$$);$ds_dang_phu_trach$$.push($email$$);let $allUsers$$,$selUsers$$;$admin$$={visible_to:null};let $visible$$=[];underscore.has($model$$.schema.paths,"visible_to")&&($condition$$.$and||($condition$$.$and=[]),$allUsers$$={visible_to:0},$selUsers$$={visible_to:2,visible_to_users:$email$$},$e$jscomp$3_key_right$$={visible_to:5,visible_to_users:($participant$$||{}).group_id},$visible$$.push($allUsers$$),
19
- $visible$$.push($selUsers$$),$visible$$.push($e$jscomp$3_key_right$$),$visible$$.push($admin$$));$e$jscomp$3_key_right$$=$email$$;$participant$$&&$participant$$.group_id&&($e$jscomp$3_key_right$$=$participant$$.group_id.toLowerCase());right.findOne({id_app:$id_app$$,email:$e$jscomp$3_key_right$$,module:$module$$},async function($allow_trang_thai_error$jscomp$3_users$$,$_right$jscomp$1__right_trang_thai$$){if($_right$jscomp$1__right_trang_thai$$&&(!1===$_right$jscomp$1__right_trang_thai$$.viewOfOther?
20
- ($visible$$.push({user_created:{$in:$ds_dang_phu_trach$$}}),$allUsers$$&&($allUsers$$.user_created={$in:$ds_dang_phu_trach$$})):$_right$jscomp$1__right_trang_thai$$.viewOfOther_user_groups&&0<$_right$jscomp$1__right_trang_thai$$.viewOfOther_user_groups.length?($allow_trang_thai_error$jscomp$3_users$$=await Participant.find({id_app:$id_app$$,group_id:{$in:$_right$jscomp$1__right_trang_thai$$.viewOfOther_user_groups}}),$ds_dang_phu_trach$$.push(...$allow_trang_thai_error$jscomp$3_users$$.map($u$$=>
21
- $u$$.email)),$visible$$.push({user_created:{$in:$ds_dang_phu_trach$$}}),$allUsers$$&&($allUsers$$.user_created={$in:$ds_dang_phu_trach$$})):($ds_dang_phu_trach$$.push(null),$ds_dang_phu_trach$$.push(void 0),$ds_dang_phu_trach$$.push("")),!0===underscore.has($model$$.schema.paths,"trang_thai")&&($_right$jscomp$1__right_trang_thai$$=$_right$jscomp$1__right_trang_thai$$.view_trang_thai))){$allow_trang_thai_error$jscomp$3_users$$=[void 0,null,""];for(let $t$$ in $_right$jscomp$1__right_trang_thai$$)$_right$jscomp$1__right_trang_thai$$[$t$$]&&
22
- $allow_trang_thai_error$jscomp$3_users$$.push($t$$);$allUsers$$?$allUsers$$.trang_thai={$in:$allow_trang_thai_error$jscomp$3_users$$}:$condition$$.trang_thai={$in:$allow_trang_thai_error$jscomp$3_users$$}}$selUsers$$&&(underscore.has($model$$.schema.paths,"of_user")&&$visible$$.push({of_user:$email$$}),underscore.has($model$$.schema.paths,"phu_trach")&&$visible$$.push({phu_trach:{$in:$ds_dang_phu_trach$$}}),underscore.has($model$$.schema.paths,"attends")&&$visible$$.push({attends:{$in:$ds_dang_phu_trach$$}}));
23
- 0<$visible$$.length&&($condition$$.$and||($condition$$.$and=[]),$condition$$.$and.push({$or:$visible$$}));$next$$(null,$condition$$,!1)})}},$options$$)};
18
+ $condition$$,$admin$$);else{let $allUsers$$,$selUsers$$,$selGroups$$,$visible$$=[];$e$jscomp$3_key_right$$=$email$$;$participant$$&&$participant$$.group_id&&($e$jscomp$3_key_right$$=$participant$$.group_id.toLowerCase());right.findOne({id_app:$id_app$$,email:$e$jscomp$3_key_right$$,module:$module$$},async function($ds_dang_phu_trach_error$$,$_right$jscomp$1__right_trang_thai$$){if($_right$jscomp$1__right_trang_thai$$&&$_right$jscomp$1__right_trang_thai$$.view){$ds_dang_phu_trach_error$$={visible_to:null};
19
+ underscore.has($model$$.schema.paths,"visible_to")&&($condition$$.$and||($condition$$.$and=[]),$allUsers$$={visible_to:0},$selUsers$$={visible_to:2,visible_to_users:$email$$},$selGroups$$={visible_to:5,visible_to_users:($participant$$||{}).group_id},$visible$$.push($allUsers$$),$visible$$.push($selUsers$$),$visible$$.push($selGroups$$),$visible$$.push($ds_dang_phu_trach_error$$));$ds_dang_phu_trach_error$$=await exports.dsDangPhuTrach($id_app$$,$email$$);$ds_dang_phu_trach_error$$.push($email$$);
20
+ if(!1===$_right$jscomp$1__right_trang_thai$$.viewOfOther)$visible$$.push({user_created:{$in:$ds_dang_phu_trach_error$$}}),$allUsers$$&&($allUsers$$.user_created={$in:$ds_dang_phu_trach_error$$});else if($_right$jscomp$1__right_trang_thai$$.viewOfOther_user_groups&&0<$_right$jscomp$1__right_trang_thai$$.viewOfOther_user_groups.length){var $allow_trang_thai_users$$=await Participant.find({id_app:$id_app$$,group_id:{$in:$_right$jscomp$1__right_trang_thai$$.viewOfOther_user_groups}});$ds_dang_phu_trach_error$$.push(...$allow_trang_thai_users$$.map($u$$=>
21
+ $u$$.email));$visible$$.push({user_created:{$in:$ds_dang_phu_trach_error$$}});$allUsers$$&&($allUsers$$.user_created={$in:$ds_dang_phu_trach_error$$})}else $ds_dang_phu_trach_error$$.push(null),$ds_dang_phu_trach_error$$.push(void 0),$ds_dang_phu_trach_error$$.push("");if(!0===underscore.has($model$$.schema.paths,"trang_thai")&&($_right$jscomp$1__right_trang_thai$$=$_right$jscomp$1__right_trang_thai$$.view_trang_thai)){$allow_trang_thai_users$$=[void 0,null,""];for(let $t$$ in $_right$jscomp$1__right_trang_thai$$)$_right$jscomp$1__right_trang_thai$$[$t$$]&&
22
+ $allow_trang_thai_users$$.push($t$$);$allUsers$$?$allUsers$$.trang_thai={$in:$allow_trang_thai_users$$}:$condition$$.trang_thai={$in:$allow_trang_thai_users$$}}$selUsers$$&&(underscore.has($model$$.schema.paths,"of_user")&&$visible$$.push({of_user:$email$$}),underscore.has($model$$.schema.paths,"phu_trach")&&$visible$$.push({phu_trach:{$in:$ds_dang_phu_trach_error$$}}),underscore.has($model$$.schema.paths,"attends")&&$visible$$.push({attends:{$in:$ds_dang_phu_trach_error$$}}))}else $visible$$.push({user_created:$email$$}),
23
+ underscore.has($model$$.schema.paths,"of_user")&&$visible$$.push({of_user:$email$$}),underscore.has($model$$.schema.paths,"phu_trach")&&$visible$$.push({phu_trach:$email$$}),underscore.has($model$$.schema.paths,"attends")&&$visible$$.push({attends:$email$$});0<$visible$$.length&&($condition$$.$and||($condition$$.$and=[]),$condition$$.$and.push({$or:$visible$$}));$next$$(null,$condition$$,!1)})}},$options$$)};
24
24
  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$$&&!0===underscore.has($model$$.schema.paths,"dataview_to_users")){$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$$});
25
25
  $dataview$$.push({dataview_to:2,dataview_to_users:$email$$});$condition$jscomp$1_e$$.$and.push({$or:$dataview$$})}$next$$(null,$condition$jscomp$1_e$$,$admin$$)})};
26
26
  exports.getFieldNotRight=async($_fields_id_app$$,$_p_email$$,$ma_ct$$)=>{if(!$_fields_id_app$$)return[];$_p_email$$=await Participant.ofApp($_fields_id_app$$,$_p_email$$);if(0<$_p_email$$.length){$_p_email$$=$_p_email$$[0].group_id;let $field_not_right$$;try{$field_not_right$$=await right.getInfo($_fields_id_app$$,{email:$_p_email$$,module:$ma_ct$$.toLowerCase()},"field_not_right")}catch($e$$){return[]}$_fields_id_app$$=[];for(let $_key$$ in $field_not_right$$)$field_not_right$$[$_key$$]&&$_fields_id_app$$.push($_key$$);
@@ -5,10 +5,11 @@ model.on("index",async function($err$$){if($err$$)return console.error("Product
5
5
  model.createTransId=($id_app$$,$sender_email$$,$receiver_email$$,$amount$$)=>{let $timestamp$$=(new Date).getTime();return cryptoJs.SHA256($id_app$$+$sender_email$$+$receiver_email$$+$amount$$.toString()+$timestamp$$).toString()};
6
6
  model.createTrans=async $data$$=>{$data$$.otherData||($data$$.otherData={});if($data$$.receiver_email===$data$$.sender_email||!$data$$.amount)throw"Ng\u01b0\u1eddi nh\u1eadn v\u00e0 ng\u01b0\u1eddi g\u1eedi ph\u1ea3i kh\u00e1c nhau v\u00e0 s\u1ed1 l\u01b0\u1ee3ng ph\u1ea3i l\u1edbn h\u01a1n 0";let $id_trans$$=model.createTransId($data$$.id_app,$data$$.sender_email,$data$$.receiver_email,$data$$.amount),$signature$$=await wallet.sign($data$$.id_app,$data$$.sender_email,{id_app:$data$$.id_app,sender_email:$data$$.sender_email,
7
7
  receiver_email:$data$$.receiver_email,amount:$data$$.amount}),$trans$$=new model({id_app:$data$$.id_app,id_trans:$id_trans$$,sender:{email:$data$$.sender_email,signature:$signature$$},receiver:{email:$data$$.receiver_email},amount:$data$$.amount,description:$data$$.description,id_ct:$data$$.otherData.id_ct,so_ct:$data$$.otherData.so_ct,ngay_ct:$data$$.otherData.ngay_ct,ma_ct:$data$$.otherData.ma_ct,tk_no:$data$$.otherData.tk_no,tk_co:$data$$.otherData.tk_co});await new Promise(($resolve$$,$reject$$)=>
8
- {$trans$$.save(async($e_kh_no_users_will_receive$$,$rs$$)=>{if($e_kh_no_users_will_receive$$)return console.log($e_kh_no_users_will_receive$$),$reject$$(Error($e_kh_no_users_will_receive$$.message));if($rs$$.tk_no&&$rs$$.tk_co){$e_kh_no_users_will_receive$$=await global.getModel("customer").findOne({id_app:$rs$$.id_app,of_user:$rs$$.receiver.email}).lean();$kh_co_notificationData_title$$=await global.getModel("customer").findOne({id_app:$rs$$.id_app,of_user:$rs$$.sender.email}).lean();let $master$$=
9
- $rs$$.toObject();$master$$.dien_giai=$master$$.description;(new PostSocai($master$$,[{tk_no:$rs$$.tk_no,tk_co:$rs$$.tk_co,tien_nt:$rs$$.amount,tien:$rs$$.amount,ma_nt:"VND",ma_kh_no:($e_kh_no_users_will_receive$$||{}).ma_kh,ma_kh_co:($kh_co_notificationData_title$$||{}).ma_kh}])).run($e$$=>{$e$$&&console.error($e$$)})}$e_kh_no_users_will_receive$$=[$rs$$.sender.email,$rs$$.receiver.email];var $kh_co_notificationData_title$$=`${$data$$.sender_email} \u0111\u00e3 chuy\u1ec3n cho ${$data$$.receiver_email} ${$data$$.amount} \u0111i\u1ec3m v\u1edbi n\u1ed9i dung: ${$data$$.description}`;
10
- if($data$$.sender_email===$data$$.id_app||$data$$.receiver_email===$data$$.id_app)$kh_co_notificationData_title$$=`${$data$$.description}`;$kh_co_notificationData_title$$={_id:$rs$$._id,id_app:$data$$.id_app,title:$kh_co_notificationData_title$$,body:$kh_co_notificationData_title$$,code:"transaction",event:"new",action:"NEW"};global.getModel("app").emitEvent($data$$.id_app,`${$kh_co_notificationData_title$$.code}:${$kh_co_notificationData_title$$.event}`,$kh_co_notificationData_title$$,null,$e_kh_no_users_will_receive$$,
11
- !0);$resolve$$($rs$$.toObject())})})};model.getTrans=async $id_trans$$=>new Promise($resolve$$=>{model.findOne({id_trans:$id_trans$$},($e$$,$rs$$)=>{$resolve$$($rs$$)})});model.deleteTrans=async $id_trans$$=>{$id_trans$$="string"===typeof $id_trans$$?{id_trans:$id_trans$$}:{...$id_trans$$};console.log("delete transaction",$id_trans$$);await model.deleteMany($id_trans$$)};
8
+ {$trans$$.save(async($e_kh_no_users_will_receive$$,$rs$$)=>{if($e_kh_no_users_will_receive$$)return console.log($e_kh_no_users_will_receive$$),$reject$$(Error($e_kh_no_users_will_receive$$.message));if($rs$$.tk_no&&$rs$$.tk_co){$e_kh_no_users_will_receive$$=await global.getModel("customer").findOne({id_app:$rs$$.id_app,of_user:$rs$$.receiver.email}).lean();$kh_co_notificationData_title$$=await global.getModel("customer").findOne({id_app:$rs$$.id_app,of_user:$rs$$.sender.email}).lean();let $ma_dvcs$$=
9
+ await global.getModel("dvcs").findOne({id_app:$rs$$.id_app}).lean(),$master$$=$rs$$.toObject();$master$$.dien_giai=$master$$.description;$master$$.ma_dvcs=(($ma_dvcs$$||{})._id||"").toString();(new PostSocai($master$$,[{tk_no:$rs$$.tk_no,tk_co:$rs$$.tk_co,tien_nt:$rs$$.amount,tien:$rs$$.amount,ma_nt:"VND",ty_gia:1,ma_kh_no:($e_kh_no_users_will_receive$$||{}).ma_kh,ma_kh_co:($kh_co_notificationData_title$$||{}).ma_kh}])).run($e$$=>{$e$$&&console.error($e$$)})}$e_kh_no_users_will_receive$$=[$rs$$.sender.email,
10
+ $rs$$.receiver.email];var $kh_co_notificationData_title$$=`${$data$$.sender_email} \u0111\u00e3 chuy\u1ec3n cho ${$data$$.receiver_email} ${$data$$.amount} \u0111i\u1ec3m v\u1edbi n\u1ed9i dung: ${$data$$.description}`;if($data$$.sender_email===$data$$.id_app||$data$$.receiver_email===$data$$.id_app)$kh_co_notificationData_title$$=`${$data$$.description}`;$kh_co_notificationData_title$$={_id:$rs$$._id,id_app:$data$$.id_app,title:$kh_co_notificationData_title$$,body:$kh_co_notificationData_title$$,
11
+ code:"transaction",event:"new",action:"NEW"};global.getModel("app").emitEvent($data$$.id_app,`${$kh_co_notificationData_title$$.code}:${$kh_co_notificationData_title$$.event}`,$kh_co_notificationData_title$$,null,$e_kh_no_users_will_receive$$,!0);$resolve$$($rs$$.toObject())})})};model.getTrans=async $id_trans$$=>new Promise($resolve$$=>{model.findOne({id_trans:$id_trans$$},($e$$,$rs$$)=>{$resolve$$($rs$$)})});
12
+ model.deleteTrans=async $id_trans$$=>{$id_trans$$="string"===typeof $id_trans$$?{id_trans:$id_trans$$}:{...$id_trans$$};console.log("delete transaction",$id_trans$$);await model.deleteMany($id_trans$$)};
12
13
  model.balance=async($email$$,$date_to$$)=>{$date_to$$||($date_to$$=new Date);$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$},{"receiver.email":$email$$}]})).map($tran$$=>$tran$$.sender.email===$email$$?0-$tran$$.amount:$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
13
14
  model.in=async($email$$,$date_to$$)=>{$date_to$$||($date_to$$=new Date);$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"receiver.email":$email$$}]})).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
14
15
  model.out=async($email$$,$date_to$$)=>{$date_to$$||($date_to$$=new Date);$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$}]})).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};model.on("index",function($err$$){$err$$?console.error("Transaction index error: %s",$err$$):console.info("Transaction indexing complete")});module.exports=model;
@@ -10,7 +10,7 @@ $_token$$,$ip_now$$),$fn$$("Your IP is not valid");if(global.configs.check_token
10
10
  global.configs.APP_SECRET)&&"public"!==$_token$$.email)try{let $decoded$$=jwt.verify($token$$,$APP_SECRET_options$$);if(!$decoded$$.user||$decoded$$.user.email!==$_token$$.email)return console.error("token is not valid",$_token$$),$fn$$("This access token is not valid")}catch($e$$){return $fn$$($e$$.message)}let $query$$={email:$_token$$.email};(new Promise(($resove$$,$reject$$)=>{setImmediate(()=>{global.clientRedis.get(`:email:${$_token$$.email}`,function($err$$,$reply$$){if($reply$$)return $resove$$(JSON.parse($reply$$));
11
11
  User.findOne($query$$).lean().exec(function($error$$,$user$$){if($error$$)return $reject$$($error$$);$user$$?$resove$$($user$$):$reject$$(`User ${$_token$$.email} is not exists`)})})})})).then($user$$=>{$user$$.current_user=$user$$.email;$user$$.token=$token$$;$user$$.admin=underscore.contains($usersAdmin$$,$user$$.email)||isSupperAdmin($user$$.email.toLowerCase());if(!1===$user$$.status)return $fn$$("This user was locked");"public"!==$_token$$.email&&$_token$$._id&&($_token$$.last_access=new Date,
12
12
  $_token$$.save());setImmediate(()=>{$fn$$(null,$user$$,$_token$$)})}).catch($e$$=>{$fn$$($e$$)})};
13
- const sendEmailTo=($email$$,$data$$)=>{$data$$.body&&validator.isEmail($email$$)&&emailService.sendHtml({to:{address:$email$$},subject:($data$$.title||"").replace(/<[^>]*>?/gm,""),html:$data$$.body||""},function($error$$){$error$$&&console.error($error$$)})},socketSendTo=async($email$$,$event_name$$,$msg$$,$exclude_token$$)=>{setImmediate(async()=>{$email$$&&[...(new Set((await Tokens.find({email:$email$$})).map($t$$=>$t$$.token)))].filter($t$$=>!$exclude_token$$||$t$$!==$exclude_token$$).forEach($token$$=>
13
+ const sendEmailTo=($email$$,$data$$)=>{$data$$.email_content&&validator.isEmail($email$$)&&emailService.sendHtml({to:{address:$email$$},subject:($data$$.title||"").replace(/<[^>]*>?/gm,""),html:$data$$.email_content},function($error$$){$error$$&&console.error($error$$)})},socketSendTo=async($email$$,$event_name$$,$msg$$,$exclude_token$$)=>{setImmediate(async()=>{$email$$&&[...(new Set((await Tokens.find({email:$email$$})).map($t$$=>$t$$.token)))].filter($t$$=>!$exclude_token$$||$t$$!==$exclude_token$$).forEach($token$$=>
14
14
  {$event_name$$&&global.clientIO[$token$$]&&global.socketIO&&async.map(global.clientIO[$token$$],($id$$,$callback$$)=>{setImmediate(()=>{global.socketIO.to($id$$).emit($event_name$$,$msg$$);$callback$$()})},()=>{})})})},socketSendToWithToken=async($token$$,$event_name$$,$msg$$)=>{setImmediate(()=>{$event_name$$&&global.clientIO[$token$$]&&global.socketIO&&global.clientIO[$token$$].forEach(function($id$$){global.socketIO.to($id$$).emit($event_name$$,$msg$$)})})};
15
15
  User.isOnline=async $email$$=>[...(new Set((await Tokens.find({email:$email$$})).map($t$$=>$t$$.token)))].find($token$$=>global.clientIO[$token$$]&&global.socketIO&&0<global.clientIO[$token$$].length)?!0:!1;
16
16
  User.initSocket=$redisAdapter_server$$=>{global.socketIO=require("socket.io")($redisAdapter_server$$,{cors:{origin:"*",methods:["GET","POST"],credentials:!0}});$redisAdapter_server$$=require("socket.io-redis");global.socketIO.adapter($redisAdapter_server$$({host:"localhost",port:6379}));global.socketIO.on("connection",function($socket$$){$socket$$.on("login",async $msg$jscomp$0$$=>{if($msg$jscomp$0$$.token){var $_token$$=await Tokens.findOne({token:$msg$jscomp$0$$.token});$_token$$&&(global.clientIO[$msg$jscomp$0$$.token]=
@@ -18,5 +18,5 @@ User.initSocket=$redisAdapter_server$$=>{global.socketIO=require("socket.io")($r
18
18
  $socket$$.on("leave",function($msg$$){$msg$$.from=$_token$$.email;socketSendTo($msg$$.to,"leave",$msg$$)}))}});$socket$$.on("disconnect",function(){for(let $token$$ in global.clientIO)global.clientIO[$token$$]=global.clientIO[$token$$].filter($id$$=>$id$$!==$socket$$.id),0===global.clientIO[$token$$].length&&delete global.clientIO[$token$$]})})};User.teststrengthPassword=$pwString$$=>5<$pwString$$.length&&/[A-Z]+/.test($pwString$$)&&/[a-z]+/.test($pwString$$)&&/[0-9]+/.test($pwString$$);
19
19
  User.teststrengthPin=$pin$$=>4===$pin$$.length&&/^-?\d+$/.test($pin$$);
20
20
  User.emitEvent=async function($email$$,$event$$,$_data$$,$push$$,$exclude_token$$){if($email$$){if("object"===typeof $_data$$){var $data$$=Object.assign({},$_data$$);$data$$.__event=$event$$}else $data$$=$_data$$;if($data$$.body&&0<=$data$$.body.indexOf("{")&&0<=$data$$.body.indexOf("}"))try{const $file$$=JSON.parse($data$$.body);$file$$.data&&(0<=$file$$.data.indexOf("data:image")?$data$$.body="Image":$data$$.body="File")}catch($e$$){console.log($e$$)}socketSendTo($email$$.toLowerCase(),$event$$,
21
- $data$$,$exclude_token$$);setImmediate(()=>{if(($data$$.title||$data$$.body)&&0!=$push$$)try{"message2"!==($data$$.code||"").toLowerCase()&&sendEmailTo($email$$.toLowerCase(),$data$$);if(!global.pushNotifyPool){let $fileWorker$$=path.dirname(__dirname)+"/workers/pushNotify.js";global.pushNotifyPool=new StaticPool($fileWorker$$)}global.pushNotifyPool.exec({data:$data$$,email:$email$$,event:$event$$,configs:{database:global.configs.database,vapidKeys:global.configs.vapidKeys}},()=>{console.log("push notifications finished")})}catch($e$$){console.error($e$$)}})}};
21
+ $data$$,$exclude_token$$);setImmediate(()=>{if(($data$$.title||$data$$.body)&&0!=$push$$)try{$data$$.email_content&&sendEmailTo($email$$.toLowerCase(),$data$$);if(!global.pushNotifyPool){let $fileWorker$$=path.dirname(__dirname)+"/workers/pushNotify.js";global.pushNotifyPool=new StaticPool($fileWorker$$)}global.pushNotifyPool.exec({data:$data$$,email:$email$$,event:$event$$,configs:{database:global.configs.database,vapidKeys:global.configs.vapidKeys}},()=>{console.log("push notifications finished")})}catch($e$$){console.error($e$$)}})}};
22
22
  module.exports=User;
@@ -1,7 +1,11 @@
1
- 'use strict';const pbl=global.getModel("pbl"),xhd=global.getModel("xhd"),dmvt=global.getModel("dmvt"),vat=global.getModel("vat"),async=require("async"),controller=require("../../controllers/controllerRPT");
1
+ 'use strict';const Pbl=global.getModel("pbl"),So1=global.getModel("so1"),Trangthai=global.getModel("trangthai"),xhd=global.getModel("xhd"),dmvt=global.getModel("dmvt"),vat=global.getModel("vat"),async=require("async"),controller=require("../../controllers/controllerRPT");
2
2
  module.exports=function($router$$){new controller($router$$,"getvc2xhd",async function($req$$,$callback$jscomp$1$$){const $condition$$=$req$$.query;if(!$condition$$.ma_thue||!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$jscomp$1$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:ma_thue,tu_ngay,den_ngay");let $_vat$$=await vat.findOne({id_app:$condition$$.id_app,ma_thue:$condition$$.ma_thue});if(!$_vat$$)return $callback$jscomp$1$$("M\u00e3 thu\u1ebf kh\u00f4ng t\u1ed3n t\u1ea1i");
3
- async.parallel({pbl:function($callback$jscomp$0$$){const $query$$={id_app:$condition$$.id_app,trang_thai:{$in:["5","6"]}};$query$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.so_ct&&($query$$.so_ct=$condition$$.so_ct);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);pbl.find($query$$).lean().exec(function($error$$,$pbls$$){if($error$$)return $callback$jscomp$0$$($error$$);async.map($pbls$$,($pbl$$,
4
- $callback$$)=>{$pbl$$.details.joinModel2($condition$$.id_app,xhd,{where:$item$$=>({details:{$elemMatch:{id_ct:$pbl$$._id,ma_vt:$item$$.ma_vt}}}),fields:[{id_xhd:"_id"}]},()=>{$pbl$$.details=$pbl$$.details.filter($d$$=>!$d$$.id_xhd);$pbl$$.details.joinModel2($condition$$.id_app,dmvt,{where:"ma_vt",fields:["ten_vt","ma_thue"]},()=>{$pbl$$.details=$pbl$$.details.filter($detail$$=>$detail$$.ma_thue===$_vat$$.ma_thue).map($detail$$=>{let $_detail$$={...$detail$$,sel:!1};$_detail$$.id_ct=$pbl$$._id.toString();
5
- $_detail$$.code_ct="PBL";$_detail$$.so_ct=$pbl$$.so_ct;$_detail$$.ngay_ct=$pbl$$.ngay_ct;$_detail$$.thue_suat=$_vat$$.thue_suat;$_detail$$.sl_xuat=$_detail$$.sl_xuat||1;$_detail$$.tt_nt=$_detail$$.tt=$_detail$$.tien;$_detail$$.tien_nt=$_detail$$.tien=$_detail$$.tt/(1+$_detail$$.thue_suat/100);$_detail$$.gia_ban_nt=$_detail$$.gia_ban=Math.roundBy($_detail$$.tien_nt/$_detail$$.sl_xuat);$_detail$$.tien_hang_nt=$_detail$$.tien_hang=Math.roundBy($_detail$$.gia_ban_nt*$detail$$.sl_xuat);$_detail$$.ty_le_ck=
6
- 0;$_detail$$.tien_ck=$_detail$$.tien_ck_nt=0;$_detail$$.tien_nt=$_detail$$.tien=$_detail$$.tien_hang_nt-$_detail$$.tien_ck_nt;$_detail$$.tien_thue_nt=$_detail$$.tien_thue=Math.roundBy($_detail$$.tien_nt*$_detail$$.thue_suat/100);return $_detail$$});$callback$$()})})},()=>{$callback$jscomp$0$$(null,$pbls$$.filter($p$$=>0<$p$$.details.length))})})}},function($error$$,$results$$){if($error$$)return $callback$jscomp$1$$($error$$);$error$$=$results$$.pbl.map($r$$=>$r$$.details).reduce(($a$$,$b$$)=>$a$$.concat($b$$),
7
- []);$callback$jscomp$1$$(null,$error$$)})})};
3
+ const $trang_thais$$=await Trangthai.find({ma_ct:{$in:["PBL","SO1"]},post:!0},{ma_trang_thai:1,ma_ct:1});async.parallel({pbl:function($callback$jscomp$0$$){const $query$$={id_app:$condition$$.id_app,trang_thai:{$in:$trang_thais$$.filter($r$$=>"PBL"==$r$$.ma_ct).map($a$$=>$a$$.ma_trang_thai)}};$query$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.so_ct&&($query$$.so_ct=$condition$$.so_ct);$condition$$.ma_kh&&
4
+ ($query$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_ct&&($query$$.ma_ct=$condition$$.ma_ct);Pbl.find($query$$).lean().exec(function($error$$,$pbls$$){if($error$$)return $callback$jscomp$0$$($error$$);async.map($pbls$$,($pbl$$,$callback$$)=>{$pbl$$.details.joinModel2($condition$$.id_app,xhd,{where:$item$$=>({details:{$elemMatch:{id_ct:$pbl$$._id,ma_vt:$item$$.ma_vt}}}),fields:[{id_xhd:"_id"}]},()=>{$pbl$$.details=$pbl$$.details.filter($d$$=>!$d$$.id_xhd);$pbl$$.details.joinModel2($condition$$.id_app,
5
+ dmvt,{where:"ma_vt",fields:["ten_vt","ma_thue"]},()=>{$pbl$$.details=$pbl$$.details.filter($detail$$=>$detail$$.ma_thue===$_vat$$.ma_thue).map($detail$$=>{let $_detail$$={...$detail$$,sel:!1};$_detail$$.id_ct=$pbl$$._id.toString();$_detail$$.code_ct="PBL";$_detail$$.so_ct=$pbl$$.so_ct;$_detail$$.ngay_ct=$pbl$$.ngay_ct;$_detail$$.thue_suat=$_vat$$.thue_suat;$_detail$$.sl_xuat=$_detail$$.sl_xuat||1;$_detail$$.tt_nt=$_detail$$.tt=$_detail$$.tien;$_detail$$.tien_nt=$_detail$$.tien=$_detail$$.tt/(1+$_detail$$.thue_suat/
6
+ 100);$_detail$$.gia_ban_nt=$_detail$$.gia_ban=Math.roundBy($_detail$$.tien_nt/$_detail$$.sl_xuat);$_detail$$.tien_hang_nt=$_detail$$.tien_hang=Math.roundBy($_detail$$.gia_ban_nt*$detail$$.sl_xuat);$_detail$$.ty_le_ck=0;$_detail$$.tien_ck=$_detail$$.tien_ck_nt=0;$_detail$$.tien_nt=$_detail$$.tien=$_detail$$.tien_hang_nt-$_detail$$.tien_ck_nt;$_detail$$.tien_thue_nt=$_detail$$.tien_thue=Math.roundBy($_detail$$.tien_nt*$_detail$$.thue_suat/100);return $_detail$$});$callback$$()})})},()=>{$callback$jscomp$0$$(null,
7
+ $pbls$$.filter($p$$=>0<$p$$.details.length))})})},so1:function($callback$jscomp$0$$){const $query$$={id_app:$condition$$.id_app,trang_thai:{$in:$trang_thais$$.filter($r$$=>"SO1"==$r$$.ma_ct).map($a$$=>$a$$.ma_trang_thai)}};$query$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.so_ct&&($query$$.so_ct=$condition$$.so_ct);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_ct&&($query$$.ma_ct=
8
+ $condition$$.ma_ct);So1.find($query$$).lean().exec(function($error$$,$so1s$$){if($error$$)return $callback$jscomp$0$$($error$$);async.map($so1s$$,($so1$$,$callback$$)=>{$so1$$.details.joinModel2($condition$$.id_app,xhd,{where:$item$$=>({details:{$elemMatch:{id_ct:$so1$$._id,ma_vt:$item$$.ma_vt}}}),fields:[{id_xhd:"_id"}]},()=>{$so1$$.details=$so1$$.details.filter($d$$=>!$d$$.id_xhd);$so1$$.details.joinModel2($condition$$.id_app,dmvt,{where:"ma_vt",fields:["ten_vt","ma_thue"]},()=>{$so1$$.details=
9
+ $so1$$.details.filter($detail$$=>$detail$$.ma_thue===$_vat$$.ma_thue).map($detail$$=>{let $_detail$$={...$detail$$,sel:!1};$_detail$$.id_ct=$so1$$._id.toString();$_detail$$.code_ct="SO1";$_detail$$.so_ct=$so1$$.so_ct;$_detail$$.ngay_ct=$so1$$.ngay_ct;$_detail$$.thue_suat=$_vat$$.thue_suat;$_detail$$.sl_xuat=$_detail$$.sl_xuat||1;$_detail$$.tt_nt=$_detail$$.tt=$_detail$$.tien;$_detail$$.tien_nt=$_detail$$.tien=$_detail$$.tt/(1+$_detail$$.thue_suat/100);$_detail$$.gia_ban_nt=$_detail$$.gia_ban=Math.roundBy($_detail$$.tien_nt/
10
+ $_detail$$.sl_xuat);$_detail$$.tien_hang_nt=$_detail$$.tien_hang=Math.roundBy($_detail$$.gia_ban_nt*$detail$$.sl_xuat);$_detail$$.ty_le_ck=0;$_detail$$.tien_ck=$_detail$$.tien_ck_nt=0;$_detail$$.tien_nt=$_detail$$.tien=$_detail$$.tien_hang_nt-$_detail$$.tien_ck_nt;$_detail$$.tien_thue_nt=$_detail$$.tien_thue=Math.roundBy($_detail$$.tien_nt*$_detail$$.thue_suat/100);return $_detail$$});$callback$$()})})},()=>{$callback$jscomp$0$$(null,$so1s$$.filter($p$$=>0<$p$$.details.length))})})}},function($error$$,
11
+ $results$$){if($error$$)return $callback$jscomp$1$$($error$$);$error$$=$results$$.pbl.map($r$$=>$r$$.details).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$callback$jscomp$1$$(null,$error$$)})})};
@@ -1,4 +1,4 @@
1
1
  'use strict';const model=global.getModel("moduleinfo"),underscore=require("underscore"),controller=require("../../controllers/controller"),{isSupperAdmin}=require("../../libs/utils");
2
2
  module.exports=function($router$$){(new controller($router$$,model,"moduleinfo",{sort:{code:1},require_id_app:!1,unique:["app","code"],onFinding:($user$$,$condition$$,$next$$)=>{$next$$(null,$condition$$)},onCreating:($user$$,$obj$$,$next$$)=>{if(!underscore.contains(configs.admins,$user$$.email)&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");$next$$(null,$obj$$)},onUpdating:($user$$,$data$$,$obj$$,$next$$)=>
3
- {if($obj$$.user_created!==$user$$.email&&0>($obj$$.allow_users||"").indexOf($user$$.email)&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");$next$$(null,$data$$,$obj$$)},onCreated:($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)},onUpdated:($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)},onDeleting:($user$$,$obj$$,$next$$)=>{if($obj$$.user_created!==$user$$.email&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");
3
+ {if(!underscore.contains(configs.admins,$user$$.email)&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");$next$$(null,$data$$,$obj$$)},onCreated:($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)},onUpdated:($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)},onDeleting:($user$$,$obj$$,$next$$)=>{if($obj$$.user_created!==$user$$.email&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");
4
4
  $next$$(null,$obj$$)},onView:($user$$,$items$$,$next$$)=>{$next$$(null,$items$$)}})).route()};
@@ -7,12 +7,12 @@ $req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress,($
7
7
  [],$user$$.local.email2=$user$$.email2,$user$$.local.picture||($user$$.local.picture="/images/avatar.jpg"),delete $user$$.token,User.find({partner:$user$$._id},{local:1}).lean().exec(async($e$$,$p$$)=>{$p$$&&$p$$.forEach(function($u$$){delete $u$$.local.password;delete $u$$.local.rspassword;delete $u$$.tokens;delete $u$$.token;delete $u$$.local.pin;$user$$.local.invited.push($u$$.local)});$user$$.local.isOnline=await User.isOnline($user$$.email);$res$$.send($user$$.local)})):$res$$.status(404).send({error:"Kh\u00f4ng t\u00ecm th\u1ea5y th\u00f4ng tin c\u1ee7a t\u00e0i kho\u1ea3n n\u00e0y"})})});
8
8
  $router$$.route("/avatar").get(function($req$$,$res$$){var $email$$=$req$$.query.email,$query$$={};async.parallel({e:function($callback$$){$email$$&&($query$$.email=$email$$);$callback$$()},t:function($callback$$){$email$$?$callback$$():Token.findOne({token:$req$$.query.access_token},function($e$$,$t$$){if($e$$)return $callback$$($e$$);$t$$&&($query$$.email=$t$$.email);$callback$$()})}},function($e$$){if($e$$)return $res$$.status(400).send({error:$e$$});let $size$$=Number($req$$.query.size)||240;
9
9
  $query$$.email||($query$$.tokens=$req$$.query.access_token);User.findOne($query$$,{picture:1}).lean().exec(function($error$$,$user$$){if($error$$)return $res$$.status(400).send($error$$);$error$$=configs.paths.images||path.join(path.dirname(path.dirname(__dirname)),"images");if($user$$&&$user$$.picture)if(0===$user$$.picture.indexOf("/getfile/")){let $imgPath$$=$user$$.picture.replace(/\/getfile\//g,"");$imgPath$$=path.join($error$$,$imgPath$$);fs.existsSync($imgPath$$)?gm($imgPath$$).resize($size$$,
10
- null).stream(function($err$$,$stdout$$){if($err$$)return $res$$.sendFile($imgPath$$);$stdout$$.pipe($res$$)}):$res$$.sendFile(path.join($error$$,"avatar.jpg"))}else 0===$user$$.picture.indexOf("http://")||0===$user$$.picture.indexOf("https://")?request.get($user$$.picture).pipe($res$$):$res$$.sendFile(path.join($error$$,"avatar.jpg"));else $res$$.sendFile(path.join($error$$,"avatar.jpg"))})})});$router$$.route("/uploadfile").post(function($req$$,$res$$){var $access_token$$=$req$$.query.access_token,
11
- $folder$$=$req$$.query.folder||"",$id_app$$=$req$$.query.id_app;if(!$req$$.files.fileupload)if($req$$.files.file)$req$$.files.fileupload=$req$$.files.file;else{$res$$.status(400).send({error:"File kh\u00f4ng t\u1ed3n t\u1ea1i"});return}var $path$$=require("path"),$ext$$=$path$$.extname($req$$.files.fileupload.path);$ext$$?($ext$$=$ext$$.toLowerCase(),".exe"===$ext$$?$res$$.status(400).send({error:"Ki\u1ec3u file n\u00e0y kh\u00f4ng \u0111\u01b0\u1ee3c ch\u1ea5p nh\u1eadn"}):findByToken($access_token$$,
10
+ null).stream(function($err$$,$stdout$$){if($err$$)return $res$$.sendFile($imgPath$$);$stdout$$.pipe($res$$)}):$res$$.sendFile(path.join($error$$,"avatar.jpg"))}else 0===$user$$.picture.indexOf("http://")||0===$user$$.picture.indexOf("https://")?request.get($user$$.picture).pipe($res$$):$res$$.sendFile(path.join($error$$,"avatar.jpg"));else $res$$.sendFile(path.join($error$$,"avatar.jpg"))})})});$router$$.route("/uploadfile").post(function($req$$,$res$$){const $access_token$$=$req$$.query.access_token;
11
+ let $folder$$=$req$$.query.folder||"";const $id_app$$=$req$$.query.id_app;if(!$req$$.files.fileupload)if($req$$.files.file)$req$$.files.fileupload=$req$$.files.file;else{$res$$.status(400).send({error:"File kh\u00f4ng t\u1ed3n t\u1ea1i"});return}const $path$$=require("path");let $ext$$=$path$$.extname($req$$.files.fileupload.path);$ext$$?($ext$$=$ext$$.toLowerCase(),".exe"===$ext$$?$res$$.status(400).send({error:"Ki\u1ec3u file n\u00e0y kh\u00f4ng \u0111\u01b0\u1ee3c ch\u1ea5p nh\u1eadn"}):findByToken($access_token$$,
12
12
  $req$$.ip||$req$$.headers["x-forwarded-for"]||$req$$.connection.remoteAddress,async($error$jscomp$2$$,$_user$$)=>{if($error$jscomp$2$$)return $res$$.status(400).send({error:$error$jscomp$2$$.message||$error$jscomp$2$$.error||$error$jscomp$2$$});if($_user$$){const $user$$=await User.findOne({email:$_user$$.email});fs.readFile($req$$.files.fileupload.path,function($err$jscomp$0$$,$data$$){if($err$jscomp$0$$)return $res$$($err$jscomp$0$$);var $originalname_p$$=$req$$.files.fileupload.originalname.split(" ").join("_");
13
13
  $err$jscomp$0$$=configs.paths.images||$path$$.dirname($path$$.dirname(__dirname))+"/images";$err$jscomp$0$$+="/";fs.existsSync($err$jscomp$0$$+$folder$$)||fs.mkdirSync($err$jscomp$0$$+$folder$$);$id_app$$&&"avatar"!=$folder$$&&($folder$$=$folder$$+"/"+$id_app$$,fs.existsSync($err$jscomp$0$$+$folder$$)||fs.mkdirSync($err$jscomp$0$$+$folder$$));let $newPath$$=$folder$$+"/"+$user$$._id.toString()+"_"+(new Date).getTime().toString()+"_"+$originalname_p$$,$path_image$$=$err$jscomp$0$$+$newPath$$;if(".png"!==
14
14
  $ext$$&&".jpeg"!==$ext$$&&".jpg"!==$ext$$&&".gif"!==$ext$$)fs.writeFile($path_image$$,$data$$,function($err$$){if($err$$)return $res$$.status(400).send($err$$.message);fs.unlink($req$$.files.fileupload.path,$e$$=>{$e$$&&console.error($e$$)});$req$$.query.json?$res$$.send({fileUrl:"/getfile/"+$newPath$$}):($res$$.writeHead(200,{"Content-Type":"text/html"}),$res$$.end("<html><head><title>/getfile/"+$newPath$$+"</title></head><body>success</body></html>"))});else{$originalname_p$$=$originalname_p$$.split(".");
15
- var $thumbPath$$=$newPath$$+".thumb."+$originalname_p$$[$originalname_p$$.length-1],$path_image_thumb$$=$err$jscomp$0$$+$thumbPath$$;gm($req$$.files.fileupload.path).size(function($error$jscomp$1$$,$value$$){if($error$jscomp$1$$)return console.log("Can't get size of image. Check imageMagick \n"+$error$jscomp$1$$),$res$$.status(400).send($error$jscomp$1$$);async.parallel([function($callback$$){$value$$&&1024<$value$$.width?gm($req$$.files.fileupload.path).resize(1024).write($path_image$$,function($error$$){$error$$&&
15
+ var $thumbPath$$=$newPath$$+".thumb."+$originalname_p$$[$originalname_p$$.length-1],$path_image_thumb$$=$err$jscomp$0$$+$thumbPath$$;gm($req$$.files.fileupload.path).size(function($error$jscomp$1$$,$value$$){if($error$jscomp$1$$)return console.log("Can't get size of image. Check imageMagick \n"+$error$jscomp$1$$),$res$$.status(400).send($error$jscomp$1$$);async.parallel([function($callback$$){$value$$&&4096<$value$$.width?gm($req$$.files.fileupload.path).resize(4096).write($path_image$$,function($error$$){$error$$&&
16
16
  console.log("Can't resize image \n"+$error$$);$callback$$($error$$)}):fs.writeFile($path_image$$,$data$$,function($err$$){$callback$$($err$$)})}],function($err$$){if($err$$)return $res$$.status(400).send($err$$);gm($path_image$$).resize(350,"350>").gravity("Center").extent(350,350).write($path_image_thumb$$,function($error$jscomp$0$$){if($error$jscomp$0$$)console.log("Kh\u00f4ng th\u1ec3 t\u1ea1o thumbnail cho h\u00ecnh \u1ea3nh n\u00e0y. Kiem tra cai dat imageMagick\n"+$error$jscomp$0$$),$res$$.status(400).send($error$jscomp$0$$);
17
17
  else{fs.unlink($req$$.files.fileupload.path,$e$$=>{$e$$&&console.error($e$$)});var $path_avatar$$="/getfile/"+$newPath$$,$path_thumb$$="/getfile/"+$thumbPath$$;"avatars"==$folder$$?($user$$.local.picture=$path_avatar$$,$user$$.picture=$user$$.local.picture,$user$$.save(function($error$$){if($error$$)return $res$$.status(400).send($error$$);$req$$.query.json?$res$$.send({image:$path_avatar$$,thumb:$path_thumb$$,fileUrl:$path_avatar$$}):($res$$.writeHead(200,{"Content-Type":"text/html"}),$res$$.end("<html><head><title>"+
18
18
  $path_avatar$$+"</title></head><body>success</body></html>"))})):$req$$.query.json?$res$$.send({image:$path_avatar$$,thumb:$path_thumb$$,fileUrl:$path_avatar$$}):($res$$.writeHead(200,{"Content-Type":"text/html"}),$res$$.end("<html><head><title>"+$path_avatar$$+"</title></head><body>success</body></html>"))}})})})}})}else $res$$.status(404).send({error:"Not found"})})):$res$$.status(400).send({error:"Ki\u1ec3u file n\u00e0y kh\u00f4ng \u0111\u01b0\u1ee3c ch\u1ea5p nh\u1eadn"})});$router$$.route("/uploadexcel").post(function($req$$,