zet-lib 1.5.22 → 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.
@@ -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 == "production"
759
- ? process.env.APP_URL + "/za/" + post.token
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
- /* //send activity
1068
- await connection.insert({
1069
- table: "zactivity",
1070
- data: {
1071
- company_id: result.company_id,
1072
- created_at: Util.now(),
1073
- created_by: result.user_id,
1074
- updated_by: result.user_id,
1075
- user_id: result.user_id,
1076
- table: MYMODEL.table,
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.5.22",
3
+ "version": "1.5.23",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"