zet-lib 1.5.23 → 1.5.24
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/zAppRouter.js +86 -12
- package/package.json +1 -1
package/lib/zAppRouter.js
CHANGED
|
@@ -707,6 +707,18 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
707
707
|
table: MYMODEL.table,
|
|
708
708
|
where: { table: data.table, id_data: data.id_data },
|
|
709
709
|
});
|
|
710
|
+
|
|
711
|
+
//change title for subject for email
|
|
712
|
+
let titleEmail = data.title || ""
|
|
713
|
+
let rowData = await connection.result({table: results[0].table, where: {id: results[0].id_data}});
|
|
714
|
+
data2 = await zRoute.viewTable(req, res, MYMODEL, rowData, true);
|
|
715
|
+
for (var key in data2) {
|
|
716
|
+
titleEmail = Util.replaceAll(titleEmail, "{{" + key + "}}", data2[key])
|
|
717
|
+
}
|
|
718
|
+
//console.log(titleEmail)
|
|
719
|
+
//end
|
|
720
|
+
|
|
721
|
+
|
|
710
722
|
if (results.length) {
|
|
711
723
|
let query = await zRoute.updateSQL(req, res, MYMODEL.table, data, {
|
|
712
724
|
id: results[0].id,
|
|
@@ -761,10 +773,10 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
761
773
|
: `http://localhost:${port}/za/${post.token}`;
|
|
762
774
|
let email = users[post.user_id].email;
|
|
763
775
|
|
|
764
|
-
post.subject = `Need Approve ${
|
|
776
|
+
post.subject = `Need Approve ${titleEmail}`;
|
|
765
777
|
post.buttonTitle = `Approve Now`;
|
|
766
778
|
post.caption = `NEED APPROVE DOCUMENT`;
|
|
767
|
-
post.title =
|
|
779
|
+
post.title = titleEmail;
|
|
768
780
|
post.link = link;
|
|
769
781
|
post.url = process.env.APP_URL;
|
|
770
782
|
post.description = `Hai ${users[post.user_id].fullname} <br>
|
|
@@ -776,7 +788,7 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
776
788
|
|
|
777
789
|
//send notification
|
|
778
790
|
//send toastr using socket.io
|
|
779
|
-
io.to(users[item].token).emit("message", "Need Approve " +
|
|
791
|
+
io.to(users[item].token).emit("message", "Need Approve " + titleEmail);
|
|
780
792
|
});
|
|
781
793
|
|
|
782
794
|
knowings.map(async (item) => {
|
|
@@ -794,9 +806,9 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
794
806
|
: `http://localhost:${port}/za/${post.token}`;
|
|
795
807
|
let email = users[post.user_id].email;
|
|
796
808
|
|
|
797
|
-
post.subject = `Need acknowledge ${
|
|
809
|
+
post.subject = `Need acknowledge ${titleEmail}`;
|
|
798
810
|
post.buttonTitle = `Acknowledge Now`;
|
|
799
|
-
post.title =
|
|
811
|
+
post.title = titleEmail
|
|
800
812
|
post.caption = `NEED ACKNOWLEDGE DOCUMENT`;
|
|
801
813
|
|
|
802
814
|
post.link = link;
|
|
@@ -810,7 +822,7 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
810
822
|
|
|
811
823
|
io.to(users[item].token).emit(
|
|
812
824
|
"message",
|
|
813
|
-
"Need Acknowledge " +
|
|
825
|
+
"Need Acknowledge " + titleEmail
|
|
814
826
|
);
|
|
815
827
|
});
|
|
816
828
|
}
|
|
@@ -856,6 +868,11 @@ router.get("/za/:token", csrfProtection, async (req, res) => {
|
|
|
856
868
|
],
|
|
857
869
|
where: { "zapprovals_details.token": token },
|
|
858
870
|
});
|
|
871
|
+
|
|
872
|
+
if(!result.length){
|
|
873
|
+
return res.send("Not Found");
|
|
874
|
+
}
|
|
875
|
+
result = result[0];
|
|
859
876
|
let approvers = result.approvers;
|
|
860
877
|
knowings = result.knowings ? result.knowings : [];
|
|
861
878
|
|
|
@@ -1009,6 +1026,15 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1009
1026
|
}
|
|
1010
1027
|
|
|
1011
1028
|
var result = results[0];
|
|
1029
|
+
//change title for subject for email
|
|
1030
|
+
let titleEmail = result.title || ""
|
|
1031
|
+
let rowData = await connection.result({table: result.table, where: {id: result.id_data}});
|
|
1032
|
+
data2 = await zRoute.viewTable(req, res, MYMODEL, rowData, true);
|
|
1033
|
+
for (var key in data2) {
|
|
1034
|
+
titleEmail = Util.replaceAll(titleEmail, "{{" + key + "}}", data2[key])
|
|
1035
|
+
}
|
|
1036
|
+
//end
|
|
1037
|
+
|
|
1012
1038
|
if (result.approvers_status == 3 || result.approvers_status == 4) {
|
|
1013
1039
|
return res.json(Util.jsonError("You have submited."));
|
|
1014
1040
|
}
|
|
@@ -1061,7 +1087,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1061
1087
|
}
|
|
1062
1088
|
//{ comments: 'yyyyy', status: '6' }
|
|
1063
1089
|
let approval_history = result.approval_history || [];
|
|
1064
|
-
approval_history.push({comments:req.body.comments, status:req.body.status, user_id:result.user_id})
|
|
1090
|
+
approval_history.push({comments:req.body.comments, status:req.body.status, user_id:result.user_id, time:Util.now()})
|
|
1065
1091
|
post.approval_history = Util.array_to_jsonb(approval_history)
|
|
1066
1092
|
await connection.update({
|
|
1067
1093
|
table: "zapprovals",
|
|
@@ -1094,7 +1120,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1094
1120
|
|
|
1095
1121
|
//send notification
|
|
1096
1122
|
if (status == 3 || status == 4) {
|
|
1097
|
-
let message = `Document ${
|
|
1123
|
+
let message = `Document ${titleEmail} has ${MYMODEL.widgets.status[status]};`;
|
|
1098
1124
|
approvers.forEach(function (item) {
|
|
1099
1125
|
io.to(users[item].token).emit("message", message);
|
|
1100
1126
|
});
|
|
@@ -1104,7 +1130,6 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1104
1130
|
//approversSigned
|
|
1105
1131
|
if (result.typee == 2) {
|
|
1106
1132
|
//get approvers has already sign
|
|
1107
|
-
|
|
1108
1133
|
approversSigned.push(result.user_id);
|
|
1109
1134
|
var newApprovers = approvers.filter((item) => {
|
|
1110
1135
|
return !approversSigned.includes(item);
|
|
@@ -1131,7 +1156,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1131
1156
|
let link = process.env.APP_URL + "/za/" + post.token;
|
|
1132
1157
|
let email = users[item].username;
|
|
1133
1158
|
|
|
1134
|
-
post.subject = `Need Approve ${
|
|
1159
|
+
post.subject = `Need Approve ${titleEmail}`;
|
|
1135
1160
|
post.buttonTitle = `Approve Now`;
|
|
1136
1161
|
post.title = result.title;
|
|
1137
1162
|
post.link = link;
|
|
@@ -1188,7 +1213,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1188
1213
|
link: "/za/" + post.token,
|
|
1189
1214
|
status_label: "Unread",
|
|
1190
1215
|
title: `Need Approve`,
|
|
1191
|
-
description:
|
|
1216
|
+
description: titleEmail,
|
|
1192
1217
|
token: post.token,
|
|
1193
1218
|
},
|
|
1194
1219
|
});
|
|
@@ -1197,7 +1222,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1197
1222
|
//send toastr using socket.io
|
|
1198
1223
|
io.to(users[item].token).emit(
|
|
1199
1224
|
"message",
|
|
1200
|
-
"Need Approve for document : " +
|
|
1225
|
+
"Need Approve for document : " + titleEmail
|
|
1201
1226
|
);
|
|
1202
1227
|
}
|
|
1203
1228
|
}
|
|
@@ -1211,6 +1236,55 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1211
1236
|
res.json(json);
|
|
1212
1237
|
});
|
|
1213
1238
|
|
|
1239
|
+
router.post('/get_approval_comments', async(req,res) => {
|
|
1240
|
+
let data = []
|
|
1241
|
+
try {
|
|
1242
|
+
//console.log(req.body);
|
|
1243
|
+
let token = req.body.token;
|
|
1244
|
+
let row = await connection.result({
|
|
1245
|
+
select:"title_id",
|
|
1246
|
+
table : "zapprovals_details",
|
|
1247
|
+
where : {
|
|
1248
|
+
token: token
|
|
1249
|
+
}
|
|
1250
|
+
})
|
|
1251
|
+
|
|
1252
|
+
let result = await connection.result({
|
|
1253
|
+
select:"approval_history",
|
|
1254
|
+
table : "zapprovals",
|
|
1255
|
+
where : {
|
|
1256
|
+
id: row.title_id
|
|
1257
|
+
}
|
|
1258
|
+
})
|
|
1259
|
+
|
|
1260
|
+
//{"{\"status\": \"6\", \"user_id\": \"192\", \"comments\": \"yayayay\"}","{\"status\": \"6\", \"user_id\": \"192\", \"comments\": \"kurang\"}","{\"status\": \"6\", \"user_id\": \"192\", \"comments\": \"oke\"}","{\"status\": \"4\", \"user_id\": \"192\", \"comments\": \"reject\"}","{\"status\": \"6\", \"user_id\": \"192\", \"comments\": \"dsfsdf\"}"}
|
|
1261
|
+
let zuser = myCache.get('zuser') || {};
|
|
1262
|
+
let approval_history = result.approval_history || [];
|
|
1263
|
+
approval_history.forEach((item) => {
|
|
1264
|
+
// Safe access dengan optional chaining dan fallback
|
|
1265
|
+
const user = zuser[item.user_id];
|
|
1266
|
+
let name = (user && (user.fullname || user.username)) || 'Unknown User';
|
|
1267
|
+
let statusName = ''
|
|
1268
|
+
if(item.status === 6){
|
|
1269
|
+
statusName = 'Comment'
|
|
1270
|
+
} else if(item.status === 4){
|
|
1271
|
+
statusName = 'Reject'
|
|
1272
|
+
} else {
|
|
1273
|
+
statusName = 'Approve'
|
|
1274
|
+
}
|
|
1275
|
+
item.statusName = statusName;
|
|
1276
|
+
item.name = name
|
|
1277
|
+
data.push(item)
|
|
1278
|
+
})
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
} catch (e) {
|
|
1282
|
+
console.log(e)
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
res.json(data)
|
|
1286
|
+
})
|
|
1287
|
+
|
|
1214
1288
|
router.get("/zdownload/zgenerator/:table", async (req, res) => {
|
|
1215
1289
|
var table = req.params.table;
|
|
1216
1290
|
var path = `${dirRoot}/public/uploads/zgenerator/${table}.json`;
|