zet-lib 1.0.58 → 1.0.60

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/zRoute.js +50 -24
  2. package/package.json +1 -1
package/lib/zRoute.js CHANGED
@@ -1049,6 +1049,34 @@ zRoute.handleSession = async (req, user) => {
1049
1049
  }
1050
1050
  }
1051
1051
 
1052
+ zRoute.selectAllowedField = (req, res, MYMODEL, arr = []) => {
1053
+ let newArr = []
1054
+ let viewRole = []
1055
+ if (MYMODEL.hasOwnProperty('hasTabs') && MYMODEL.hasTabs) {
1056
+ let roles = myCache.get('ROLES') || {}
1057
+ let myrole = roles[res.locals.roleId]
1058
+ let tabsRole = myrole.tabs || {}
1059
+ if (tabsRole.hasOwnProperty(MYMODEL.table) && tabsRole[MYMODEL.table]) {
1060
+ viewRole = tabsRole[MYMODEL.table].view
1061
+ }
1062
+ if (viewRole.length > 0) {
1063
+ viewRole.map((item, index) => {
1064
+ if (!item) {
1065
+ newArr = [...newArr, ...MYMODEL.tabsDetail[`arr${index}`]]
1066
+ }
1067
+ })
1068
+ } else {
1069
+ MYMODEL.tabs.map((_, index) => {
1070
+ newArr = [...newArr, ...MYMODEL.tabsDetail[`arr${index}`]]
1071
+ })
1072
+ }
1073
+ let fixedArr = arr.filter((item) => !newArr.includes(item))
1074
+ arr = fixedArr
1075
+ }
1076
+
1077
+ return arr
1078
+ }
1079
+
1052
1080
  zRoute.excelQuery = async (req, res, MYMODEL) => {
1053
1081
  let virtuals = []
1054
1082
  for (var key in MYMODEL.widgets) {
@@ -1132,7 +1160,9 @@ zRoute.excelQuery = async (req, res, MYMODEL) => {
1132
1160
  if (zall) {
1133
1161
  fields = arr
1134
1162
  }
1135
- console.log(select)
1163
+
1164
+ fields = zRoute.selectAllowedField(req, res, MYMODEL, fields)
1165
+ //console.log('fields::',fields)
1136
1166
 
1137
1167
  const ztype = reqQuery.ztype == 1 ? true : false
1138
1168
  if (ztype) {
@@ -1536,29 +1566,25 @@ zRoute.listDataTable = async (req, res, objData = {}) => {
1536
1566
  const columns = Object.prototype.hasOwnProperty.call(objData, 'columns') ? objData.columns : body.columns
1537
1567
  let whereArray = []
1538
1568
  if (objData.hasOwnProperty('whereArray')) {
1539
- if (typeof objData.whereArray === 'object') {
1540
- whereArray = objData.whereArray
1541
- } else if (typeof objData.whereArray) {
1542
- whereArray = objData.whereArray(req, res)
1543
- }
1544
- } else {
1545
- whereArray.push({
1546
- field: 'company_id',
1547
- option: '=',
1548
- value: res.locals.companyId,
1549
- operator: 'AND',
1550
- })
1551
- columns.forEach(function (item) {
1552
- if (item.search.value) {
1553
- whereArray.push({
1554
- field: fields[item.data],
1555
- option: MYMODEL.options[fields[item.data]],
1556
- value: item.search.value,
1557
- operator: 'AND',
1558
- })
1559
- }
1560
- })
1569
+ whereArray.push(objData['whereArray'])
1561
1570
  }
1571
+
1572
+ whereArray.push({
1573
+ field: 'company_id',
1574
+ option: '=',
1575
+ value: res.locals.companyId,
1576
+ operator: 'AND',
1577
+ })
1578
+ columns.forEach(function (item) {
1579
+ if (item.search.value) {
1580
+ whereArray.push({
1581
+ field: fields[item.data],
1582
+ option: MYMODEL.options[fields[item.data]],
1583
+ value: item.search.value,
1584
+ operator: 'AND',
1585
+ })
1586
+ }
1587
+ })
1562
1588
  const orderColumn = fields[body.order[0].column] == 'actionColumn' ? 'id' : fields[body.order[0].column] == 'no' ? 'id' : fields[body.order[0].column] == 'actionColum' ? 'id' : fields[body.order[0].column]
1563
1589
  const rows = await connection.results({
1564
1590
  select: select,
@@ -1574,7 +1600,7 @@ zRoute.listDataTable = async (req, res, objData = {}) => {
1574
1600
  whereArray: whereArray,
1575
1601
  })
1576
1602
  let datas = []
1577
- const zRole = objData.zRole || {}
1603
+ const zRole = objData.zRole || require('./zRole')
1578
1604
  const levels = objData.hasOwnProperty('levels') ? objData.levels : zRole.myLevel(req, res, MYMODEL.table)
1579
1605
  if (objData.hasOwnProperty('datas')) {
1580
1606
  datas = objData.datas(body, rows, fields, relations, levels)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.0.58",
3
+ "version": "1.0.60",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"