zet-lib 1.5.21 → 1.5.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/views/router.txt +3 -0
- package/lib/zAppRouter.js +39 -49
- package/lib/zRoute.js +19 -18
- package/package.json +1 -1
package/lib/views/router.txt
CHANGED
|
@@ -91,9 +91,12 @@ router.get('/preview/:token', async (req, res) => {
|
|
|
91
91
|
let row = await connection.result({table: results[0].table, where: {id: results[0].id_data}});
|
|
92
92
|
data2 = await zRoute.viewTable(req, res, MYMODEL, row, true);
|
|
93
93
|
template = data.template;
|
|
94
|
+
let title = data.title || ""
|
|
94
95
|
for (var key in data2) {
|
|
95
96
|
template = Util.replaceAll(template, "{{" + key + "}}", data2[key])
|
|
97
|
+
title = Util.replaceAll(title, "{{" + key + "}}", data2[key])
|
|
96
98
|
}
|
|
99
|
+
data.title = title;
|
|
97
100
|
var details = await connection.results({table: "zapprovals_details", where: {title_id: results[0].id}});
|
|
98
101
|
if (details.length) {
|
|
99
102
|
footers = await zRoute.approversFooter(details);
|
package/lib/zAppRouter.js
CHANGED
|
@@ -647,8 +647,10 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
647
647
|
"id"
|
|
648
648
|
);
|
|
649
649
|
try {
|
|
650
|
+
//console.log(req.body)
|
|
650
651
|
let userId = res.locals.userId;
|
|
651
652
|
let data = zRoute.post(req, res, MYMODEL)[MYMODEL.table];
|
|
653
|
+
//console.log(data)
|
|
652
654
|
let validator = zRoute.validator(data, MYMODEL);
|
|
653
655
|
if (validator.status == 0) return res.json(validator.message);
|
|
654
656
|
if (data.status == 2) {
|
|
@@ -754,10 +756,9 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
754
756
|
token: Util.uuid(),
|
|
755
757
|
};
|
|
756
758
|
await zRoute.insertSQL(req, res, "zapprovals_details", post);
|
|
757
|
-
let link =
|
|
758
|
-
env
|
|
759
|
-
|
|
760
|
-
: `http://localhost:${port}/za/${post.token}`;
|
|
759
|
+
let link = env == "production"
|
|
760
|
+
? process.env.APP_URL + "/za/" + post.token
|
|
761
|
+
: `http://localhost:${port}/za/${post.token}`;
|
|
761
762
|
let email = users[post.user_id].email;
|
|
762
763
|
|
|
763
764
|
post.subject = `Need Approve ${data.title}`;
|
|
@@ -767,10 +768,8 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
767
768
|
post.link = link;
|
|
768
769
|
post.url = process.env.APP_URL;
|
|
769
770
|
post.description = `Hai ${users[post.user_id].fullname} <br>
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
We have some document for you.<br>
|
|
773
|
-
Please click the link above to view the document.`;
|
|
771
|
+
We have some document for you.<br>
|
|
772
|
+
Please click the link above to view the document.`;
|
|
774
773
|
|
|
775
774
|
post.note = `If you click the link, it's will be automatically acknowledged`;
|
|
776
775
|
Mail.approval(req, res, post, email);
|
|
@@ -803,10 +802,8 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
803
802
|
post.link = link;
|
|
804
803
|
post.url = process.env.APP_URL;
|
|
805
804
|
post.description = `Hai ${users[post.user_id].fullname} <br>
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
We have some document for you.<br>
|
|
809
|
-
Please click the link above to view the document.`;
|
|
805
|
+
We have some document for you.<br>
|
|
806
|
+
Please click the link above to view the document.`;
|
|
810
807
|
|
|
811
808
|
post.note = `If you click the link, it's will be automatically acknowledged`;
|
|
812
809
|
Mail.approval(req, res, post, email);
|
|
@@ -818,6 +815,7 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
818
815
|
});
|
|
819
816
|
}
|
|
820
817
|
} catch (err) {
|
|
818
|
+
console.log(err)
|
|
821
819
|
if (Object.prototype.hasOwnProperty.call(err, "sqlMessage")) {
|
|
822
820
|
json = Util.flashError(err.sqlMessage);
|
|
823
821
|
} else {
|
|
@@ -935,10 +933,13 @@ router.get("/za/:token", csrfProtection, async (req, res) => {
|
|
|
935
933
|
where: { id: result.id_data },
|
|
936
934
|
});
|
|
937
935
|
data = await zRoute.viewTable(req, res, MYMODEL, row);
|
|
936
|
+
let title = result.title || ""
|
|
938
937
|
template = result.template;
|
|
939
938
|
for (var key in data) {
|
|
940
939
|
template = Util.replaceAll(template, "{{" + key + "}}", data[key]);
|
|
940
|
+
title = Util.replaceAll(title, "{{" + key + "}}", data[key])
|
|
941
941
|
}
|
|
942
|
+
result.title = title;
|
|
942
943
|
footers = await zRoute.approversFooter(details);
|
|
943
944
|
|
|
944
945
|
//send activity
|
|
@@ -1058,30 +1059,38 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1058
1059
|
if (status == 4) {
|
|
1059
1060
|
post.status = 4;
|
|
1060
1061
|
}
|
|
1062
|
+
//{ comments: 'yyyyy', status: '6' }
|
|
1063
|
+
let approval_history = result.approval_history || [];
|
|
1064
|
+
approval_history.push({comments:req.body.comments, status:req.body.status, user_id:result.user_id})
|
|
1065
|
+
post.approval_history = Util.array_to_jsonb(approval_history)
|
|
1061
1066
|
await connection.update({
|
|
1062
1067
|
table: "zapprovals",
|
|
1063
1068
|
data: post,
|
|
1064
1069
|
where: { id: result.ide },
|
|
1065
1070
|
});
|
|
1071
|
+
// 6 comment 4 reject
|
|
1072
|
+
//update ke table data yang dipakai
|
|
1073
|
+
let status_approval_table = 2
|
|
1074
|
+
if(req.body.status == 4){
|
|
1075
|
+
status_approval_table = 22
|
|
1076
|
+
} else {
|
|
1077
|
+
if(result.approvers.length ==1){
|
|
1078
|
+
status_approval_table =21;
|
|
1079
|
+
} else {
|
|
1080
|
+
status_approval_table =11;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1066
1083
|
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
id_data: result.ide,
|
|
1078
|
-
status: status,
|
|
1079
|
-
status_label: MYMODEL.widgets.status.fields[status],
|
|
1080
|
-
title: MYMODEL.widgets.status.fields[status],
|
|
1081
|
-
description: comments,
|
|
1082
|
-
data: JSON.stringify(post),
|
|
1083
|
-
},
|
|
1084
|
-
});*/
|
|
1084
|
+
await connection.update({
|
|
1085
|
+
table : result.table,
|
|
1086
|
+
data:{
|
|
1087
|
+
approval_history:Util.array_to_jsonb(approval_history),
|
|
1088
|
+
approval_status:status_approval_table
|
|
1089
|
+
},
|
|
1090
|
+
where : {
|
|
1091
|
+
id: result.id_data
|
|
1092
|
+
}
|
|
1093
|
+
})
|
|
1085
1094
|
|
|
1086
1095
|
//send notification
|
|
1087
1096
|
if (status == 3 || status == 4) {
|
|
@@ -1184,25 +1193,6 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1184
1193
|
},
|
|
1185
1194
|
});
|
|
1186
1195
|
|
|
1187
|
-
//send todolist
|
|
1188
|
-
/*await connection.insert({
|
|
1189
|
-
table: "ztodolist",
|
|
1190
|
-
data: {
|
|
1191
|
-
company_id: result.company_id,
|
|
1192
|
-
created_at: Util.now(),
|
|
1193
|
-
created_by: employee_user[result.user_id].user_id,
|
|
1194
|
-
updated_by: employee_user[result.user_id].user_id,
|
|
1195
|
-
user_id: item,
|
|
1196
|
-
table: MYMODEL.table,
|
|
1197
|
-
id_data: result.ide,
|
|
1198
|
-
status: 1,
|
|
1199
|
-
link: "/za/" + post.token,
|
|
1200
|
-
status_label: "Unread",
|
|
1201
|
-
title: `Need Approve`,
|
|
1202
|
-
description: result.title,
|
|
1203
|
-
users: JSON.stringify(approvers),
|
|
1204
|
-
},
|
|
1205
|
-
});*/
|
|
1206
1196
|
|
|
1207
1197
|
//send toastr using socket.io
|
|
1208
1198
|
io.to(users[item].token).emit(
|
package/lib/zRoute.js
CHANGED
|
@@ -5548,43 +5548,43 @@ zRoute.approversFooter = async (results, noActivity) => {
|
|
|
5548
5548
|
const MYMODELS = myCache.get("MYMODELS");
|
|
5549
5549
|
let MYMODEL = MYMODELS.zapprovals_details;
|
|
5550
5550
|
let users = Util.arrayToObject(
|
|
5551
|
-
|
|
5552
|
-
|
|
5551
|
+
await connection.results({ table: "zuser" }),
|
|
5552
|
+
"id"
|
|
5553
5553
|
);
|
|
5554
5554
|
let html = "";
|
|
5555
5555
|
let id = 0;
|
|
5556
|
-
let knowings = []
|
|
5557
|
-
|
|
5556
|
+
let knowings = [];
|
|
5557
|
+
let approvals = [];
|
|
5558
5558
|
results.forEach(function (result) {
|
|
5559
5559
|
if (result.type == 2) {
|
|
5560
5560
|
let html = "";
|
|
5561
5561
|
html += `<span class="status-approver">${
|
|
5562
|
-
|
|
5562
|
+
MYMODEL.widgets.status.fields[result.status]
|
|
5563
5563
|
}</span>`;
|
|
5564
5564
|
html += `<p > <span style="text-decoration: underline;">${
|
|
5565
|
-
|
|
5565
|
+
users[result.user_id].fullname
|
|
5566
5566
|
}</span><span class="small-time"> ${
|
|
5567
|
-
|
|
5567
|
+
users[result.user_id].position ? users[result.user_id].position : ''
|
|
5568
5568
|
}</span></p>`;
|
|
5569
5569
|
knowings.push(html);
|
|
5570
5570
|
}
|
|
5571
5571
|
if (result.type == 1) {
|
|
5572
5572
|
let html = "";
|
|
5573
5573
|
let sign =
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5574
|
+
users[result.user_id].verify_signed && result.status == 3
|
|
5575
|
+
? `<img src="${process.env.APP_URL}/uploads/zuser/${
|
|
5576
|
+
users[result.user_id].verify_signed
|
|
5577
|
+
}" width="200">`
|
|
5578
|
+
: MYMODEL.widgets.status.fields[result.status];
|
|
5579
5579
|
//var sign = "";
|
|
5580
5580
|
html += `<span class="status-approver">${sign}</span>`;
|
|
5581
5581
|
html += `<p class="footer-title"> <span style="text-decoration: underline;">${
|
|
5582
|
-
|
|
5582
|
+
users[result.user_id].fullname
|
|
5583
5583
|
}</span><span class="small-time"> ${
|
|
5584
|
-
|
|
5584
|
+
users[result.user_id].position ? users[result.user_id].position : ''
|
|
5585
5585
|
} <br> ${Util.dateFormat(
|
|
5586
|
-
|
|
5587
|
-
|
|
5586
|
+
result.updated_at,
|
|
5587
|
+
"DD MMM YYYY HH:mm"
|
|
5588
5588
|
)}</span></p>
|
|
5589
5589
|
`;
|
|
5590
5590
|
approvals.push(html);
|
|
@@ -5611,7 +5611,7 @@ zRoute.approversFooter = async (results, noActivity) => {
|
|
|
5611
5611
|
return div;
|
|
5612
5612
|
};
|
|
5613
5613
|
|
|
5614
|
-
html += `<div class="row"><div class="col-12 text-center "><h5 class="knowing">
|
|
5614
|
+
html += `<div class="row"><div class="col-12 text-center "><h5 class="knowing">Approve</h5></div></div>`;
|
|
5615
5615
|
html += `<div class="row d-flex justify-content-start align-items-end">`;
|
|
5616
5616
|
let divClass = divColumn(approvals.length);
|
|
5617
5617
|
approvals.forEach(function (item) {
|
|
@@ -5623,7 +5623,7 @@ zRoute.approversFooter = async (results, noActivity) => {
|
|
|
5623
5623
|
|
|
5624
5624
|
const knowingDiv = divColumn(knowings.length);
|
|
5625
5625
|
if (knowings.length) {
|
|
5626
|
-
html += `<div class="row align-items-end"><div class="col-12 text-center mt-5"><h5 class="knowing">
|
|
5626
|
+
html += `<div class="row align-items-end"><div class="col-12 text-center mt-5"><h5 class="knowing">Acknowledge</h5></div></div>`;
|
|
5627
5627
|
html += `<div class="row">`;
|
|
5628
5628
|
knowings.forEach(function (item) {
|
|
5629
5629
|
html += `<div class="${knowingDiv}">`;
|
|
@@ -5635,6 +5635,7 @@ zRoute.approversFooter = async (results, noActivity) => {
|
|
|
5635
5635
|
return html;
|
|
5636
5636
|
};
|
|
5637
5637
|
|
|
5638
|
+
|
|
5638
5639
|
/*
|
|
5639
5640
|
cache models in so it's no need call database repeatly
|
|
5640
5641
|
*/
|