zet-lib 3.0.9 → 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 +55 -28
  2. package/package.json +1 -1
@@ -44,44 +44,71 @@ router.get('/', async function (req, res, next) {
44
44
  company_id : companyId
45
45
  }
46
46
  });
47
- if (rows.length > 0) {
48
- hasAccessMenu = true;
49
- //check id changes
50
- let rowsChanges = rows.filter((item) => item.active == 1);
51
- idChanges = rowsChanges[0].id;
52
- if (id) {
53
- await connection.update({
54
- table : "zmenu",
55
- data: {
56
- active:0
57
- },
58
- where : {
59
- company_id: companyId
60
- }
61
- });
62
- await connection.update({
47
+ if(rows.length == 0){
48
+ //copy from companyId;
49
+ let copyMenu = await connection.result({
50
+ table : "zmenu",
51
+ where : {
52
+ company_id : 1
53
+ }
54
+ })
55
+ if(copyMenu){
56
+ copyMenu.json = JSON.stringify(copyMenu.json);
57
+ copyMenu.updated_by = res.locals.userId;
58
+ copyMenu.created_by = res.locals.userId;
59
+ copyMenu.created_at = Util.now();
60
+ copyMenu.updated_at = Util.now();
61
+ copyMenu.company_id = companyId;
62
+ delete copyMenu.id;
63
+ await connection.insert({
63
64
  table : "zmenu",
64
- data : {
65
- active : 1,
66
- },
67
- where : {
68
- id: id
69
- }
65
+ data : copyMenu
70
66
  });
71
- } else {
72
- id =1;
73
- let selected = rows.filter(item=>item.active == 1)[0] || {}
74
- id = selected.id;
75
- name = selected.name;
76
67
  }
68
+ rows= await connection.results({
69
+ table: "zmenu",
70
+ where : {
71
+ company_id : companyId
72
+ }
73
+ });
77
74
  }
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;
103
+ }
104
+
78
105
  findArr = await connection.results({
79
106
  table:"zmenu",
80
107
  where: {
81
108
  id:id
82
109
  }
83
110
  });
84
- arr = findArr[0].json;
111
+ arr = findArr && findArr.length > 0 && findArr[0].json ? findArr[0].json : arr;
85
112
  let refresh = 0;
86
113
  if (id != idChanges) {
87
114
  refresh = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "3.0.9",
3
+ "version": "3.1.1",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"