flexbiz-server 12.3.8 → 12.3.9
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 +1 -1
- package/server/actions/mailtemplate.js +142 -0
- package/server/actions/schedule.js +23 -0
- package/server/controllers/controller.js +21 -14
- package/server/images/avatar.jpg +0 -0
- package/server/images/others/noimage.png +0 -0
- package/server/images/picture.png +0 -0
- package/server/modules/lists/ls-like-module.js +1 -3
- package/server/modules/vouchers/vo-hd2.js +68 -71
- package/server/modules/vouchers/vo-so1.js +27 -29
- package/server/modules/vouchers/vo-so7.js +14 -18
- package/server/modules/vouchers/vo-so9.js +78 -80
package/package.json
CHANGED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
var email = require('../libs/email');
|
|
2
|
+
var parseTemplate = require('../libs/parse-template').parseTemplate;
|
|
3
|
+
const async =require('async');
|
|
4
|
+
var Mailsent = global.getModel('mailsent');
|
|
5
|
+
var Customer = global.getModel('customer');
|
|
6
|
+
var Lienhe = global.getModel('lienhe');
|
|
7
|
+
var Link = global.getModel('link');
|
|
8
|
+
const underscore =require("underscore");
|
|
9
|
+
var mailtemplate = global.getModel("mailtemplate");
|
|
10
|
+
let model = {
|
|
11
|
+
}
|
|
12
|
+
model.send = (obj,done)=>{
|
|
13
|
+
//begin send email
|
|
14
|
+
|
|
15
|
+
email.getAccount(obj.account_id, function(e, account) {
|
|
16
|
+
|
|
17
|
+
if (e) {
|
|
18
|
+
console.error("Find email account",e);
|
|
19
|
+
//return done();
|
|
20
|
+
}
|
|
21
|
+
if(!obj.to) obj.to =[]
|
|
22
|
+
if(obj.address){
|
|
23
|
+
obj.to.push({address:obj.address,name:obj.address});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async.mapSeries(obj.to, function(to, callback) {
|
|
27
|
+
var obj4parse = {};
|
|
28
|
+
underscore.extend(obj4parse, obj);
|
|
29
|
+
if(obj.data){
|
|
30
|
+
underscore.extend(obj4parse, obj.data);
|
|
31
|
+
}
|
|
32
|
+
obj4parse.receiver = to;
|
|
33
|
+
if(!obj4parse.cid) obj4parse.cid ="1";
|
|
34
|
+
if(!obj4parse.receiver._id) obj4parse.receiver._id = "1";
|
|
35
|
+
|
|
36
|
+
parseTemplate(obj4parse.mail.html, obj4parse, function(error, html) {
|
|
37
|
+
if (error) return callback(error);
|
|
38
|
+
email.sendHtml({account: account, to: to,cc:obj.cc,bcc:obj.bcc, subject: obj4parse.subject, html: html,attachments:obj4parse.attachments},function(error, info) {
|
|
39
|
+
if (error) {
|
|
40
|
+
error = error.toString();
|
|
41
|
+
if (error.indexOf('ENOTFOUND') >= 0) {
|
|
42
|
+
callback(error);
|
|
43
|
+
}else {
|
|
44
|
+
callback();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}else {
|
|
48
|
+
//save mail sent
|
|
49
|
+
obj4parse.mail.html = html;
|
|
50
|
+
obj4parse.mail.text = obj4parse.mail.html.replace(/<(?:.|\n)*?>/gm, '');
|
|
51
|
+
|
|
52
|
+
if (obj4parse.mail.text) {
|
|
53
|
+
if (obj4parse.mail.text.length > 128) {
|
|
54
|
+
obj4parse.small_text = obj4parse.mail.text.substring(0, 128) + '...';
|
|
55
|
+
}else {
|
|
56
|
+
obj4parse.small_text = obj4parse.mail.text;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
obj4parse.to = [to];
|
|
60
|
+
obj4parse.date_created = new Date();
|
|
61
|
+
obj4parse.date_updated = new Date();
|
|
62
|
+
delete obj4parse._id;
|
|
63
|
+
if(!obj4parse.account_id){
|
|
64
|
+
obj4parse.account_id = "SYSTEM";
|
|
65
|
+
}
|
|
66
|
+
var mailsent = new Mailsent(obj4parse);
|
|
67
|
+
mailsent.save(function(e, sent) {
|
|
68
|
+
if (e) return console.log(e);
|
|
69
|
+
//create link
|
|
70
|
+
async.parallel({
|
|
71
|
+
contact: function(callback) {
|
|
72
|
+
Lienhe.find({email: to.address, id_app: sent.id_app}).lean().exec(function(e, lhs) {
|
|
73
|
+
if (lhs) {
|
|
74
|
+
async.mapSeries(lhs, function(lh, callback) {
|
|
75
|
+
var link = new Link({id_app: sent.id_app, collection_a: 'lienhe', id_a: lh._id, collection_b: 'mailsent', id_b: sent._id});
|
|
76
|
+
link.save(function(e) {
|
|
77
|
+
if (e) console.log(e);
|
|
78
|
+
callback();
|
|
79
|
+
});
|
|
80
|
+
},function(e, rs) {
|
|
81
|
+
callback();
|
|
82
|
+
});
|
|
83
|
+
}else {
|
|
84
|
+
callback();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
cust: function(callback) {
|
|
89
|
+
Customer.find({email: to.address, id_app: sent.id_app}).lean().exec(function(e, lhs) {
|
|
90
|
+
if (lhs) {
|
|
91
|
+
async.mapSeries(lhs, function(lh, callback) {
|
|
92
|
+
var link = new Link({id_app: sent.id_app, collection_a: 'customer', id_a: lh._id, collection_b: 'mailsent', id_b: sent._id});
|
|
93
|
+
link.save(function(e) {
|
|
94
|
+
if (e) console.log(e);
|
|
95
|
+
callback();
|
|
96
|
+
});
|
|
97
|
+
},function(e, rs) {
|
|
98
|
+
callback();
|
|
99
|
+
});
|
|
100
|
+
}else {
|
|
101
|
+
callback();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
},function(e, r) {
|
|
107
|
+
//callback(e,r)
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
callback();
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
},function(e, rs) {
|
|
115
|
+
done(e,rs);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
model.actions ={
|
|
121
|
+
send:(campaign,obj_ev,step,next)=>{
|
|
122
|
+
setImmediate(()=>{
|
|
123
|
+
if(obj_ev && obj_ev.lienhe){
|
|
124
|
+
mailtemplate.findById(step.model_id).lean().exec((e,template)=>{
|
|
125
|
+
if(template){
|
|
126
|
+
template.to = [{name:obj_ev.lienhe.ten_lien_he,address:obj_ev.lienhe.email,_id:obj_ev.lienhe._id}];
|
|
127
|
+
template.cid = campaign._id.toString();
|
|
128
|
+
model.send(template,(e)=>{
|
|
129
|
+
next();
|
|
130
|
+
})
|
|
131
|
+
}else{
|
|
132
|
+
next();
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
}else{
|
|
136
|
+
next();
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
module.exports = model;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
let waitevent = global.getModel("waitevent");
|
|
3
|
+
let model = {
|
|
4
|
+
|
|
5
|
+
}
|
|
6
|
+
model.actions ={
|
|
7
|
+
run:(campaign,obj_ev,step,next)=>{
|
|
8
|
+
waitevent.findById(step.model_id).lean().exec((e,event)=>{
|
|
9
|
+
if(event){
|
|
10
|
+
let delay=event.exfields["schedule"];
|
|
11
|
+
setTimeout(()=>{
|
|
12
|
+
globalEvents.emit("schedule_" + campaign._id + "_" + step._id,obj_ev);
|
|
13
|
+
},(delay||0)*60*1000);
|
|
14
|
+
}
|
|
15
|
+
next();
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = model;
|
|
@@ -47,18 +47,25 @@ $title$$;try{$title$$=evalute($ds_nguoi_duyet_str_func$$,{master:$obj$$,data:$ob
|
|
|
47
47
|
evalute($str_func$$,{master:$obj$$,data:$obj$$,preRequest:$preRequest$$});if(!_.isArray($ds_nguoi_duyet_str_func$$)){console.error("danh s\u00e1ch ng\u01b0\u1eddi duy\u1ec7t ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng, hi\u1ec7n t\u1ea1i \u0111ang l\u00e0",$ds_nguoi_duyet_str_func$$);return}}catch($e$$){console.error("request approve",$e$$,$ds_nguoi_duyet_str_func$$);return}if($approveData$$.approve_users_custom)try{let $str_func$$=$approveData$$.approve_users_custom;0>$str_func$$.indexOf("return ")&&($str_func$$=
|
|
48
48
|
`return ${$str_func$$}`);let $ds_nguoi_duyet_custom$$=evalute($str_func$$,{master:$obj$$,data:$obj$$,preRequest:$preRequest$$});$ds_nguoi_duyet_custom$$&&(_.isArray($ds_nguoi_duyet_custom$$)?$ds_nguoi_duyet_str_func$$=[...$ds_nguoi_duyet_str_func$$,...$ds_nguoi_duyet_custom$$]:console.error("danh s\u00e1ch ng\u01b0\u1eddi duy\u1ec7t ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng, hi\u1ec7n t\u1ea1i \u0111ang l\u00e0",$ds_nguoi_duyet_custom$$))}catch($e$$){console.error("request approve",$e$$,$approveData$$.approve_users_custom)}if($ds_nguoi_duyet_str_func$$&&
|
|
49
49
|
0!==$ds_nguoi_duyet_str_func$$.length&&($ds_nguoi_duyet_str_func$$=[...(new Set($ds_nguoi_duyet_str_func$$))],$obj$$.trang_thai==$approveData$$.trang_thai)){let $user_approves$$=$ds_nguoi_duyet_str_func$$.map($nguoi_duyet$$=>({email:$nguoi_duyet$$,name:$nguoi_duyet$$}));$user_approves$$.joinModel2($obj$$.id_app,Participant,{where:"email",fields:"name"},()=>{[$user_request$$].joinModel2($obj$$.id_app,Participant,{where:"email",fields:"name"},()=>{Approve.request($user_request$$,$user_approves$$,$title$$,
|
|
50
|
-
$obj$$,$e$$=>{$e$$&&console.error("error create request approve:",$e$$.message||$e$$)},$update_after_approve$$,$approveData$$.template_content,$update_after_deny$$)})})}})});$next$$(null,$obj$$)}async import($user$$,$id_app$$,$data$$,$callback_main$$,$options$$={replace:!0,req:null}){const $ctrl$$=this,$model$$=$ctrl$$.model;let $replace$$=$options$$.replace,$rows_error$$=[];
|
|
51
|
-
$modelJoins$$=[];$info$$&&(await $
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
$
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
$obj$$,$e$$=>{$e$$&&console.error("error create request approve:",$e$$.message||$e$$)},$update_after_approve$$,$approveData$$.template_content,$update_after_deny$$)})})}})});$next$$(null,$obj$$)}async import($user$$,$id_app$$,$data$$,$callback_main$$,$options$$={replace:!0,req:null}){const $ctrl$$=this,$model$$=$ctrl$$.model;let $replace$$=$options$$.replace,$rows_error$$=[];var $custs_listInfo_tk_dt$$=global.getModel("listinfo");let $info$$=await $custs_listInfo_tk_dt$$.findOne({code:$ctrl$$.name.toLowerCase()}).lean(),
|
|
51
|
+
$modelJoins$$=[];$info$$&&(await $custs_listInfo_tk_dt$$.updateModel($info$$,$ctrl$$.model),$modelJoins$$=($info$$.fields||[]).filter($f$$=>$f$$.ref_model&&"_id"==$f$$.ref_field));$data$$=$data$$.filter($row$$=>{let $has_data$$=!1;for(let $key$$ in $row$$)if($row$$[$key$$]){$has_data$$=!0;break}return $has_data$$});$custs_listInfo_tk_dt$$=[];$model$$.schema.paths.ma_kh&&($custs_listInfo_tk_dt$$=$data$$.filter($r$$=>$r$$.ten_kh));$model$$.schema.paths.details&&($custs_listInfo_tk_dt$$=$custs_listInfo_tk_dt$$.concat($data$$.map($v$$=>
|
|
52
|
+
$v$$.details||[]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).filter($r$$=>$r$$.ten_kh)));$custs_listInfo_tk_dt$$=$custs_listInfo_tk_dt$$.map($kh$$=>{$kh$$.ma_kh||($kh$$.ma_kh=$kh$$.ten_kh.replace(/[^\w\s]/gi,"").split(" ").join("").toUpperCase());return{ma_kh:$kh$$.ma_kh,ten_kh:$kh$$.ten_kh,dia_chi:$kh$$.dia_chi||"",dien_thoai:$kh$$.dien_thoai||"",ma_so_thue:$kh$$.ma_so_thue||""}});$custs_listInfo_tk_dt$$=await $custs_listInfo_tk_dt$$.asyncGroupBy(["ma_kh","ten_kh","dia_chi","dien_thoai","ma_so_thue"],
|
|
53
|
+
[]);for($dvts_kh$$ of $custs_listInfo_tk_dt$$)$dvts_kh$$.id_app=$id_app$$,$dvts_kh$$.user_created=$user$$.email,await global.getModel("customer").asyncCreateCustomer($dvts_kh$$);var $dvts_kh$$=[];$model$$.schema.paths.ma_kho&&($dvts_kh$$=$data$$.filter($r$$=>$r$$.ten_kho));$model$$.schema.paths.details&&($dvts_kh$$=$dvts_kh$$.concat($data$$.map($v$$=>$v$$.details||[]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).filter($r$$=>$r$$.ten_kho)));$dvts_kh$$=$dvts_kh$$.map($kh$$=>{$kh$$.ma_kho||($kh$$.ma_kho=
|
|
54
|
+
$kh$$.ten_kho.replace(/[^\w\s]/gi,"").split(" ").join("").toUpperCase());return{ma_kho:$kh$$.ma_kho,ten_kho:$kh$$.ten_kho}});$dvts_kh$$=await $dvts_kh$$.asyncGroupBy(["ma_kho","ten_kho"],[]);for($kho_vts$$ of $dvts_kh$$)$kho_vts$$.id_app=$id_app$$,$kho_vts$$.user_created=$user$$.email,$kho_vts$$.status=!0,await global.getModel("dmkho").findOne({id_app:$id_app$$,ma_kho:$kho_vts$$.ma_kho}).lean()||await global.getModel("dmkho").create($kho_vts$$);var $kho_vts$$=[];$model$$.schema.paths.ma_vt&&($kho_vts$$=
|
|
55
|
+
$data$$.filter($r$$=>$r$$.ma_vt&&$r$$.ten_vt&&$r$$.ma_dvt));$model$$.schema.paths.details&&($kho_vts$$=$kho_vts$$.concat($data$$.map($v$$=>$v$$.details||[]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).filter($r$$=>$r$$.ma_vt&&$r$$.ten_vt&&$r$$.ma_dvt)));$kho_vts$$=$kho_vts$$.map($vt$$=>({ma_vt:$vt$$.ma_vt,ten_vt:$vt$$.ten_vt,ma_dvt:$vt$$.ma_dvt,user_created:$user$$.email}));$kho_vts$$=await $kho_vts$$.asyncGroupBy(["ma_vt","ten_vt","ma_dvt"],[]);$dvts_kh$$=await $kho_vts$$.asyncGroupBy(["ma_dvt"],[]);
|
|
56
|
+
for($dvt_tk_vt$$ of $dvts_kh$$)$dvt_tk_vt$$.id_app=$id_app$$,$dvt_tk_vt$$.ten_dvt=$dvt_tk_vt$$.ma_dvt,$dvt_tk_vt$$.status=!0,$dvt_tk_vt$$.user_created=$user$$.email,await global.getModel("dmdvt").findOne({ma_dvt:$dvt_tk_vt$$.ma_dvt,id_app:$id_app$$}).lean()||(console.log("create dvt",$dvt_tk_vt$$),await global.getModel("dmdvt").create($dvt_tk_vt$$));var $dvt_tk_vt$$=(await global.getModel("account").findOne({id_app:$id_app$$,loai:1,tk:{$regex:"^156",$option:"i"}},{tk:1}).lean()||{}).tk;$dvts_kh$$=
|
|
57
|
+
(await global.getModel("account").findOne({id_app:$id_app$$,loai:1,tk:{$regex:"^632",$option:"i"}},{tk:1}).lean()||{}).tk;$custs_listInfo_tk_dt$$=(await global.getModel("account").findOne({id_app:$id_app$$,loai:1,tk:{$regex:"^511",$option:"i"}},{tk:1}).lean()||{}).tk;for(let $vt$$ of $kho_vts$$)$vt$$.id_app=$id_app$$,$vt$$.tk_vt=$dvt_tk_vt$$,$vt$$.tk_gv=$dvts_kh$$,$vt$$.tk_dt=$custs_listInfo_tk_dt$$,$vt$$.status=!0,$vt$$.user_created=$user$$.email,await global.getModel("dmvt").findOne({ma_vt:$vt$$.ma_vt,
|
|
58
|
+
id_app:$id_app$$}).lean()||(console.log("create product",$vt$$),await global.getModel("dmvt").create($vt$$),await global.getModel("dmqddvt").create({id_app:$id_app$$,status:!0,ma_vt:$vt$$.ma_vt,ma_dvt:$vt$$.ma_dvt,tu:1,ma:1}));$data$$.forEach($r$$=>{delete $r$$.ten_dvcs;global.mongoose.Types.ObjectId.isValid($r$$._id)&&delete $r$$._id});await $data$$.filter($r$$=>$r$$.ma_dvcs).asyncJoinModel2($id_app$$,global.getModel("dvcs"),{where:{ma_dvcs:"_id"},fields:"ten_dvcs"});async.mapSeries($data$$,function($row$$,
|
|
59
|
+
$callback$$){const $row_keys$$=Object.keys($row$$);$row_keys$$.filter($key$$=>$ctrl$$.model.schema.paths[$key$$]).forEach($key$$=>{let $data_type$$=$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase(),$data_value$$=$row$$[$key$$];if($data_value$$&&_.isString($data_value$$)&&("mixed"==$data_type$$||"array"==$data_type$$)&&($data_value$$=$data_value$$.trim(),0==$data_value$$.indexOf("[")||0==$data_value$$.indexOf("{")))try{$row$$[$key$$]=JSONParser($data_value$$)}catch($e$$){delete $row$$[$key$$],
|
|
60
|
+
console.error("Error parse data",$e$$)}});setImmediate(async()=>{for(let $i$$=0;$i$$<$modelJoins$$.length;$i$$++){let $field_ref$$=$modelJoins$$[$i$$];if($row$$[$field_ref$$.name]){let $new_data_ref$$=await global.getModel("originimportid").findOne({id_app:$id_app$$,old_id:$row$$[$field_ref$$.name]}).lean();$new_data_ref$$&&($row$$[$field_ref$$.name]=$new_data_ref$$.new_id)}}delete $row$$.__v;let $old_id$$=$row$$._id;$row$$.ma_dvcs&&!$row$$.ten_dvcs&&delete $row$$.ma_dvcs;$row$$.id_app&&$id_app$$!=
|
|
61
|
+
$row$$.id_app&&delete $row$$._id;delete $row$$.id_app;if($replace$$&&($ctrl$$.unique&&0<$ctrl$$.unique.length||$row$$._id)){let $query$$={};if($ctrl$$.unique&&0<$ctrl$$.unique.length){if($ctrl$$.options.unique_imp&&null!=$row$$[$ctrl$$.options.unique_imp]&&void 0!=$row$$[$ctrl$$.options.unique_imp]&&""!=$row$$[$ctrl$$.options.unique_imp])$query$$[$ctrl$$.options.unique_imp]=$row$$[$ctrl$$.options.unique_imp];else if($ctrl$$.unique.forEach(function($k$$){0<=$row_keys$$.indexOf($k$$)&&($query$$[$k$$]=
|
|
62
|
+
$row$$[$k$$],void 0==$query$$[$k$$]&&delete $query$$[$k$$])}),1>Object.keys($query$$).length)return $callback$$("Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt, D\u1eef li\u1ec7u kh\u00f4ng t\u1ed3n t\u1ea1i \u0111\u1ee7 c\u00e1c gi\u00e1 tr\u1ecb:"+$ctrl$$.unique.join(","));0!=$ctrl$$.require_id_app&&($query$$.id_app=$id_app$$)}else $query$$._id=$row$$._id;$ctrl$$.model.find($query$$).lean().exec(function($error$$,$rss$$){if($error$$)return $callback$$($error$$);if(1<$rss$$.length)return $callback$$("Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt, \u0111\u1ed1i t\u01b0\u1ee3ng "+
|
|
63
|
+
Object.values($query$$).join("-")+" \u0111\u00e3 t\u1ed3n t\u1ea1i nhi\u1ec1u h\u01a1n m\u1ed9t l\u1ea7n");setImmediate(async()=>{let $foundObject$$;1===$rss$$.length&&($foundObject$$=$rss$$[0]);$foundObject$$?($row$$.id_app=$foundObject$$.id_app,$row$$._id=$foundObject$$._id.toString(),($ctrl$$.unique||[]).forEach(function($k$$){$row$$[$k$$]=$foundObject$$[$k$$]}),update($user$$,$ctrl$$,$foundObject$$._id,$row$$,function($e$$){if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[{error:$e$$.error||
|
|
64
|
+
$e$$,code:$e$$.code}]);$rows_error$$.push({row:$row$$,error:$_e$$})}$callback$$()},"import",$options$$.req,"import")):create($user$$,$ctrl$$,$row$$,function($e$$,$new_row$$){setImmediate(async()=>{if($e$$){var $_e$jscomp$1_i$$=$e$$;underscore.isArray($_e$jscomp$1_i$$)||($_e$jscomp$1_i$$=[{error:$e$$.error||$e$$,code:$e$$.code}]);$rows_error$$.push({row:$row$$,error:$_e$jscomp$1_i$$})}else if($row$$._id_new__=$new_row$$._id.toString(),$old_id$$)for(await global.getModel("originimportid").findOneAndUpdate({id_app:$new_row$$.id_app,
|
|
65
|
+
old_id:$old_id$$},{id_app:$new_row$$.id_app,old_id:$old_id$$,new_id:$new_row$$._id.toString()},{new:!0,upsert:!0}),$_e$jscomp$1_i$$=0;$_e$jscomp$1_i$$<$data$$.length;$_e$jscomp$1_i$$++){const $_r$$=$data$$[$_e$jscomp$1_i$$];for(let $key$$ in $_r$$)"_id"!=$key$$&&$_r$$[$key$$]==$old_id$$&&($_r$$[$key$$]=$new_row$$._id.toString(),$_r$$._id_new__&&await $model$$.updateMany({_id:$_r$$._id_new__},{[$key$$]:$new_row$$._id.toString()}))}$callback$$()})},$row$$._id,$options$$.req,"import")})})}else create($user$$,
|
|
66
|
+
$ctrl$$,$row$$,function($e$$,$new_row$$){setImmediate(async()=>{if($e$$){console.error("error import data, creating...",$e$$);var $_e$jscomp$2_i$$=$e$$;underscore.isArray($_e$jscomp$2_i$$)||($_e$jscomp$2_i$$=[{error:$e$$.error||$e$$,code:$e$$.code}]);$rows_error$$.push({error:$_e$jscomp$2_i$$})}else if($row$$._id_new__=$new_row$$._id.toString(),$old_id$$)for(await global.getModel("originimportid").findOneAndUpdate({id_app:$new_row$$.id_app,old_id:$old_id$$},{id_app:$new_row$$.id_app,old_id:$old_id$$,
|
|
67
|
+
new_id:$new_row$$._id.toString()},{new:!0,upsert:!0}),$_e$jscomp$2_i$$=0;$_e$jscomp$2_i$$<$data$$.length;$_e$jscomp$2_i$$++){const $_r$$=$data$$[$_e$jscomp$2_i$$];for(let $key$$ in $_r$$)"_id"!=$key$$&&$_r$$[$key$$]==$old_id$$&&($_r$$[$key$$]=$new_row$$._id.toString(),$_r$$._id_new__&&await $model$$.updateMany({_id:$_r$$._id_new__},{[$key$$]:$new_row$$._id.toString()}))}$callback$$()})},$row$$._id,$options$$.req,"import")})},function($error$$){setImmediate(()=>{if($error$$)return $callback_main$$($error$$);
|
|
68
|
+
$callback_main$$(null,{rows_imported:$data$$.length-$rows_error$$.length,rows_error:$rows_error$$})})})}postData($obj$$,$callback$$,$options$$={}){return controller.postData($obj$$,this,$callback$$,$options$$)}pushNotification($_obj$$,$eventName$$="new",$old_obj$$=null,$justFireEvents$$=!1,$options$$={title:"",data:{}}){return pushNotification(this,$_obj$$,$eventName$$,$old_obj$$,$justFireEvents$$,$options$$)}}controller.prototype.__proto__=EventEmitter.prototype;
|
|
62
69
|
const getNextSequence=async function($id_app$$,$ma_ct$$,$field$$,$callback$$,$options$$={}){var $condition_qct_qcts$$={status:!0,field:$field$$,id_app:$id_app$$,$and:[{$or:[{ma_ct:"#",ma_ct_khac:{$regex:$ma_ct$$,$options:"i"}},{cac_ma_ct:$ma_ct$$.toLowerCase()},{ma_ct:$ma_ct$$.toUpperCase()}]}]};$options$$.id_qct&&($condition_qct_qcts$$._id=$options$$.id_qct);if($options$$.ngay_ct){let $start_date$$=moment($options$$.ngay_ct).startOf("date").toDate(),$end_date$$=moment($options$$.ngay_ct).endOf("date").toDate();
|
|
63
70
|
$condition_qct_qcts$$.$and.push({$or:[{tu_ngay:null},{tu_ngay:{$lte:$end_date$$}}]});$condition_qct_qcts$$.$and.push({$or:[{den_ngay:null},{den_ngay:{$gte:$start_date$$}}]})}$options$$.toObject&&($options$$=$options$$.toObject());$condition_qct_qcts$$=await dmqct.find($condition_qct_qcts$$).lean();const $keys$$=Object.keys($options$$),$qct$$=$condition_qct_qcts$$.find($qct$$=>{if($qct$$.dieu_kien&&0<$keys$$.length)try{let $str_func$$=$qct$$.dieu_kien;if(0<=$str_func$$.indexOf("async "))return!1;0!==
|
|
64
71
|
$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);return evalute($str_func$$,{...$options$$,master:{...$options$$},moment,numeral})}catch($e$$){return console.error("Error find quyen chung tu",$e$$,$qct$$.dieu_kien),!1}else return!0});let $code$$=$qct$$?$qct$$._id.toString():$field$$;counter.getNextSequence($id_app$$,$ma_ct$$,$code$$,async function($error$$,$rs$$){if($error$$)console.error("auto create code for",$ma_ct$$,$code$$,$error$$),$callback$$($error$$);else{if($qct$$){let $tien_to$$=
|
|
@@ -192,12 +199,12 @@ $e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e
|
|
|
192
199
|
global.getModel("file");try{var $_data$jscomp$0$$=await $file$$.findOne({_id:$dir_root_templates_id_file$$});$_data$jscomp$0$$||$res$$.status(400).send({error:"Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu"});let $file_name$$=$_data$jscomp$0$$.file.name,$root$$=configs.paths.uploads;$root$$||($root$$=__dirname,$root$$=path.dirname($root$$),$root$$=path.join($root$$,"uploads"));$templatePath$$=path.join($root$$,$file_name$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||"Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu"})}}else $templatePath$$=
|
|
193
200
|
path.dirname($dir_root_templates_id_file$$)+$rs$jscomp$0$$.file_mau_in;if(!$templatePath$$||!fs.existsSync($templatePath$$))return $res$$.status(400).send({error:"File m\u1eabu kh\u00f4ng t\u1ed3n t\u1ea1i"});let $ext$$=$templatePath$$.split(".").pop();"xlsx"===$ext$$?excelReport($templatePath$$,$data4export$$,function($e$$,$result$$){setImmediate(()=>{if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.setHeader("Content-Type",
|
|
194
201
|
"application/vnd.openxmlformats");$res$$.setHeader("Content-Disposition","attachment; filename="+$ctrl$$.name+".xlsx");$res$$.end($result$$,"binary")})},{timezone:configs.timezone||"Asia/Ho_Chi_Minh"}):($_data$jscomp$0$$=$data4export$$[0],$_data$jscomp$0$$.datasource={...$_data$jscomp$0$$},$_data$jscomp$0$$.company={...$_app$$},textReport($templatePath$$,$_data$jscomp$0$$,function($e$$,$result$$){setImmediate(()=>{if($e$$)return console.error("exportToExcel textreport",$e$$),$e$$.error?$res$$.status(400).send($e$$):
|
|
195
|
-
$res$$.status(400).send({error:$e$$.message||$e$$});"docx"===$ext$$?($res$$.setHeader("Content-Type","application/vnd.openxmlformats-officedocument.wordprocessingml.document"),$res$$.setHeader("Content-Disposition","attachment; filename="+$ctrl$$.name+".docx"),$res$$.write($result$$,"binary"),$res$$.end(null,"binary")):$res$$.send($result$$)})}))}})})})})})})})};
|
|
202
|
+
$res$$.status(400).send({error:$e$$.message||$e$$});"docx"===$ext$$?($res$$.setHeader("Content-Type","application/vnd.openxmlformats-officedocument.wordprocessingml.document"),$res$$.setHeader("Content-Disposition","attachment; filename="+$ctrl$$.name+".docx"),$res$$.write($result$$,"binary"),$res$$.end(null,"binary")):$res$$.send($result$$)})}))}})})})})})})})};
|
|
196
203
|
controller.prototype.importFromGoogleSheet=function(){const $name$$=this.name;let $ctrl$$=this;this.router.route(`${this.route_name}/import/googlesheet`).get(async function($error$jscomp$26_req$$,$res$$,$next$$){let {spreadsheetid:$spreadsheetid$$,range:$range$$}=$error$jscomp$26_req$$.query;if(!$spreadsheetid$$)return $res$$.status(400).send({error:"Thi\u1ebfu tham s\u1ed1 spreadsheetid"});0<=$spreadsheetid$$.indexOf("https://docs.google.com/spreadsheets/d/")&&($spreadsheetid$$=$spreadsheetid$$.replace("https://docs.google.com/spreadsheets/d/",
|
|
197
204
|
""),$spreadsheetid$$=$spreadsheetid$$.split("/")[0]);if(!$spreadsheetid$$)return $res$$.status(400).send({error:"spreadsheetId is not valid"});$range$$||($range$$="Sheet1");let $session$$=$error$jscomp$26_req$$.session;if(!0===$session$$["import_json_"+$name$$])return $res$$.status(400).send({error:"\u0110ang x\u1eed l\u00fd d\u1eef li\u1ec7u"});$session$$["import_json_"+$name$$]=!0;var $app$jscomp$3_google_credentials_id_app$$=$error$jscomp$26_req$$.query.id_app;$app$jscomp$3_google_credentials_id_app$$=
|
|
198
205
|
await global.getModel("app").findOne({_id:$app$jscomp$3_google_credentials_id_app$$}).lean();if(!$app$jscomp$3_google_credentials_id_app$$)return $res$$.status(400).send({error:"id_app kh\u00f4ng t\u1ed3n t\u1ea1i"});$app$jscomp$3_google_credentials_id_app$$=$app$jscomp$3_google_credentials_id_app$$.google_credentials||configs.google_credentials;if(!$app$jscomp$3_google_credentials_id_app$$)return $res$$.status(400).send({error:"Ch\u01b0a khai b\u00e1o th\u00f4ng tin truy c\u1eadp google apis"});
|
|
199
206
|
let $listinfo_code$$=($error$jscomp$26_req$$.query.listinfo_code||$ctrl$$.name).toLowerCase(),$listinfo$$=await global.getModel("listinfo").findOne({code:$listinfo_code$$}).lean();if(!$listinfo$$||!$listinfo$$.fields||0==$listinfo$$.fields.length)return $res$$.status(400).send({error:"API n\u00e0y kh\u00f4ng c\u00f3 th\u00f4ng tin listinfo"});let $credentials$$;try{$credentials$$="string"==typeof $app$jscomp$3_google_credentials_id_app$$?JSONParser($app$jscomp$3_google_credentials_id_app$$):$app$jscomp$3_google_credentials_id_app$$;
|
|
200
|
-
const {client_email:$client_email$$,private_key:$private_key$$}=$credentials
|
|
207
|
+
const {client_email:$client_email$$,private_key:$private_key$$}=$credentials$$,{google:$google$$}=require("googleapis"),$auth$$=new $google$$.auth.JWT($client_email$$,null,$private_key$$,["https://www.googleapis.com/auth/spreadsheets.readonly"]),$response$$=await $google$$.sheets({version:"v4",auth:$auth$$}).spreadsheets.values.get({spreadsheetId:$spreadsheetid$$,range:$range$$});$session$$["import_json_"+$name$$]=!1;if(0==$response$$.data.values.length)return $res$$.status(400).send({error:"Sheet n\u00e0y kh\u00f4ng c\u00f3 d\u1eef li\u1ec7u"});
|
|
201
208
|
let $columns$$=$response$$.data.values[0].map($c$$=>{let $field$$=$listinfo$$.fields.find($f$$=>$f$$.name.toLowerCase()==($c$$||"").toString().toLowerCase());return $field$$?$field$$.name:($field$$=$listinfo$$.fields.find($f$$=>$f$$.header.toLowerCase()==($c$$||"").toString().toLowerCase()))?$field$$.name:$c$$}),$data$$=$response$$.data.values.slice(1).map($row$$=>{let $n_row$$={};$columns$$.forEach(($c$$,$index$$)=>{$n_row$$[$c$$]=$row$$[$index$$]});return $n_row$$});$error$jscomp$26_req$$.data=
|
|
202
209
|
$data$$;$next$$()}catch($e$$){return $error$jscomp$26_req$$=(($e$$.response||{}).data||{}).error||$e$$,$session$$["import_json_"+$name$$]=!1,$credentials$$&&403==$error$jscomp$26_req$$.code?$res$$.status(400).send({error:`Kh\u00f4ng th\u1ec3 truy c\u1eadp v\u00e0o google sheet. H\u00e3y ph\u00e2n quy\u1ec1n cho t\u00e0i kho\u1ea3n ${$credentials$$.client_email} c\u00f3 quy\u1ec1n \u0111\u1ecdc google sheet tr\u00ean`}):$res$$.status(400).send($error$jscomp$26_req$$)}},function($req$$,$res$$,$next$$){let $session$$=
|
|
203
210
|
$req$$.session,$data$$=$req$$.data;if($ctrl$$.options.onImport)$ctrl$$.options.onImport($req$$.user,$data$$,[],function($e$$,$new_data$$){setImmediate(()=>{if($e$$)return $session$$["import_json_"+$name$$]=!1,console.error("onImport from json:",$e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$req$$.data=$new_data$$||$data$$;$next$$()})});else $req$$.data=$data$$,$next$$()},function($req$$,$res$$){let $data$$=$req$$.data;setImmediate(()=>{log.create({id_app:$req$$.user.current_id_app,
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
'use strict';const model=global.getModel("like_module"),controller=require("../../controllers/controller")
|
|
2
|
-
module.exports=function($router$$){(new controller($router$$,model,"like_module",{unique:["id_app","user_created","module"],replaceIfExists:!0,notNeedRight:!0,onFinding:function($user$$,$condition$$,$next$$){$condition$$.user_created=$user$$.email;$next$$(null,$condition$$)},onFound:function($user$$,$condition$$,$items$$,$next$$){const $ms$$=underscore.values(menu.getModules());$items$$.forEach(function($item$$){const $i$$=underscore.find($ms$$,function($m$$){return $m$$.path==$item$$.module});$i$$&&
|
|
3
|
-
($item$$.module_obj=$i$$)});$next$$(null,$items$$)}})).route()};
|
|
1
|
+
'use strict';const model=global.getModel("like_module"),controller=require("../../controllers/controller");module.exports=function($router$$){(new controller($router$$,model,"like_module",{unique:["id_app","user_created","module"],replaceIfExists:!0,notNeedRight:!0,onFinding:function($user$$,$condition$$,$next$$){$condition$$.user_created=$user$$.email;$next$$(null,$condition$$)}})).route()};
|