zet-lib 3.1.0 → 3.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.
Files changed (2) hide show
  1. package/lib/zMenuRouter.js +37 -31
  2. package/package.json +1 -1
@@ -53,6 +53,7 @@ router.get('/', async function (req, res, next) {
53
53
  }
54
54
  })
55
55
  if(copyMenu){
56
+ copyMenu.json = JSON.stringify(copyMenu.json);
56
57
  copyMenu.updated_by = res.locals.userId;
57
58
  copyMenu.created_by = res.locals.userId;
58
59
  copyMenu.created_at = Util.now();
@@ -64,45 +65,50 @@ router.get('/', async function (req, res, next) {
64
65
  data : copyMenu
65
66
  });
66
67
  }
68
+ rows= await connection.results({
69
+ table: "zmenu",
70
+ where : {
71
+ company_id : companyId
72
+ }
73
+ });
67
74
  }
68
- if (rows.length > 0) {
69
- hasAccessMenu = true;
70
- //check id changes
71
- let rowsChanges = rows.filter((item) => item.active == 1);
72
- idChanges = rowsChanges[0].id;
73
- if (id) {
74
- await connection.update({
75
- table : "zmenu",
76
- data: {
77
- active:0
78
- },
79
- where : {
80
- company_id: companyId
81
- }
82
- });
83
- await connection.update({
84
- table : "zmenu",
85
- data : {
86
- active : 1,
87
- },
88
- where : {
89
- id: id
90
- }
91
- });
92
- } else {
93
- id =1;
94
- let selected = rows.filter(item=>item.active == 1)[0] || {}
95
- id = selected.id;
96
- name = selected.name;
97
- }
75
+ hasAccessMenu = true;
76
+ //check id changes
77
+ let rowsChanges = rows.filter((item) => item.active == 1);
78
+ idChanges = rowsChanges.length > 0 ? rowsChanges[0].id : null;
79
+ if (id) {
80
+ await connection.update({
81
+ table : "zmenu",
82
+ data: {
83
+ active:0
84
+ },
85
+ where : {
86
+ company_id: companyId
87
+ }
88
+ });
89
+ await connection.update({
90
+ table : "zmenu",
91
+ data : {
92
+ active : 1,
93
+ },
94
+ where : {
95
+ id: id
96
+ }
97
+ });
98
+ } else {
99
+ id =1;
100
+ let selected = rows.filter(item=>item.active == 1)[0] || {}
101
+ id = selected.id;
102
+ name = selected.name;
98
103
  }
104
+
99
105
  findArr = await connection.results({
100
106
  table:"zmenu",
101
107
  where: {
102
108
  id:id
103
109
  }
104
110
  });
105
- arr = findArr[0].json;
111
+ arr = findArr && findArr.length > 0 && findArr[0].json ? findArr[0].json : arr;
106
112
  let refresh = 0;
107
113
  if (id != idChanges) {
108
114
  refresh = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"