zet-lib 1.0.89 → 1.0.91

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/connection.js CHANGED
@@ -48,7 +48,7 @@ const orderByFn = (obj) => {
48
48
 
49
49
  const whereFn = (obj) => {
50
50
  const where = obj.where || {}
51
- //[{field:"your_field",option:"=>",value:"12",operator:"AND",isJSON : false}]
51
+ //[{field:"your_field",option:"=>",value:"12",operator:"AND",type:"text,json,date"}]
52
52
  const whereArray = obj.whereArray || []
53
53
  let increment = 1
54
54
  let arr = [],
@@ -61,30 +61,43 @@ const whereFn = (obj) => {
61
61
  wherequery = arr.length ? wherequery.join(' AND ') : ''
62
62
  if (whereArray.length) {
63
63
  let andOr = wherequery ? ' AND ' : ''
64
- whereArray.forEach((item, index) => {
65
- if (index > 0) andOr = ''
64
+ whereArray.map((item, index) => {
65
+ let type = !item.type ? 'text' : item.type
66
+ if (index > 0) {
67
+ andOr = ''
68
+ }
66
69
  let operator = !item.operator ? ' AND ' : item.operator
67
- if (index == whereArray.length - 1) operator = ''
68
- const field = item.field.indexOf('.') > -1 ? item.field : ` "${item.field}" `
70
+ if (index == whereArray.length - 1) {
71
+ operator = ''
72
+ }
73
+ let fields = ''
74
+ if (type == 'date') {
75
+ field = item.field.indexOf('.') > -1 ? item.field + '::text ' : ` ${item.field}::text `
76
+ } else {
77
+ field = item.field.indexOf('.') > -1 ? item.field : ` "${item.field}" `
78
+ }
69
79
  //is JSON is field is JSON
70
80
  //JSON_CONTAINS(color, '"Red"' ,'$')
71
81
  if (item.isJSON) {
72
82
  wherequery += andOr + ` JSON_CONTAINS(${field}, '"${item.value}"' ,'$') ${operator}`
73
83
  } else {
74
- if (item.option.includes('{{value}}')) {
75
- item.option = item.option.replace('{{value}}', `$${increment}`)
76
- wherequery += `${andOr} ${field} ${item.option} ${operator}`
77
- } else if (item.option.includes('$')) {
78
- wherequery += `${andOr} ${field} ${item.option} ${operator}`
84
+ if (type == 'json') {
85
+ wherequery += andOr + ` JSON_CONTAINS(${field}, '"${item.value}"' ,'$') ${operator}`
79
86
  } else {
80
- wherequery += `${andOr} ${field} ${item.option} $${increment} ${operator}`
81
- }
82
-
83
- let itemValue = item.value
84
- if (item.option == '=') {
85
- itemValue = Util.replaceAll(itemValue, '%', '')
87
+ if (item.option.includes('{{value}}')) {
88
+ item.option = item.option.replace('{{value}}', `$${increment}`)
89
+ wherequery += `${andOr} ${field} ${item.option} ${operator}`
90
+ } else if (item.option.includes('$')) {
91
+ wherequery += `${andOr} ${field} ${item.option} ${operator}`
92
+ } else {
93
+ wherequery += `${andOr} ${field} ${item.option} $${increment} ${operator}`
94
+ }
95
+ let itemValue = item.value
96
+ if (item.option == '=') {
97
+ itemValue = Util.replaceAll(itemValue, '%', '')
98
+ }
99
+ arr.push(itemValue)
86
100
  }
87
- arr.push(itemValue)
88
101
  }
89
102
  increment++
90
103
  })
@@ -101,7 +114,7 @@ const whereFn = (obj) => {
101
114
  connection.results = async (obj) => {
102
115
  const select = obj.select || '*'
103
116
  const table = obj.table || ''
104
- //[{field:"your_field",option:"=>",value:"12",operator:"AND",isJSON : false}]
117
+ //[{field:"your_field",option:"=>",value:"12",operator:"AND",type:"text,json,date"}]
105
118
  const statement = obj.statement || ''
106
119
  const limit = obj.limit ? ` LIMIT ${obj.limit} ` : ''
107
120
  const offset = obj.hasOwnProperty('offset') ? ` OFFSET ${obj.offset} ` : obj.limit ? 'OFFSET 0' : ''
package/lib/zRoute.js CHANGED
@@ -1196,6 +1196,9 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
1196
1196
  if (!zall) {
1197
1197
  obj.limit = body.length
1198
1198
  obj.offset = body.start
1199
+ } else {
1200
+ obj.limit = 50000
1201
+ obj.offset = 0
1199
1202
  }
1200
1203
  rows = await connection.results(obj)
1201
1204
  } else {
@@ -1614,6 +1617,15 @@ zRoute.listDataTable = async (req, res, objData = {}) => {
1614
1617
  const relations = await zRoute.relations(req, res, MYMODEL.table)
1615
1618
  const select = Object.prototype.hasOwnProperty.call(objData, 'select') ? objData.select : Util.selectParser(fields, MYMODEL)
1616
1619
  const columns = Object.prototype.hasOwnProperty.call(objData, 'columns') ? objData.columns : body.columns
1620
+ const asDate = []
1621
+ for (let key in MYMODEL.widgets) {
1622
+ if (MYMODEL.widgets[key].name == 'datetime') {
1623
+ asDate.push(key)
1624
+ }
1625
+ if (MYMODEL.widgets[key].name == 'datepicker') {
1626
+ asDate.push(key)
1627
+ }
1628
+ }
1617
1629
  let whereArray = []
1618
1630
  if (objData.hasOwnProperty('whereArray')) {
1619
1631
  whereArray.push(objData['whereArray'])
@@ -1624,13 +1636,19 @@ zRoute.listDataTable = async (req, res, objData = {}) => {
1624
1636
  value: res.locals.companyId,
1625
1637
  operator: 'AND',
1626
1638
  })
1639
+
1627
1640
  columns.forEach(function (item) {
1628
1641
  if (item.search.value) {
1642
+ let astype = 'text'
1643
+ if (asDate.includes(fields[item.data])) {
1644
+ astype = 'date'
1645
+ }
1629
1646
  whereArray.push({
1630
1647
  field: fields[item.data],
1631
1648
  option: MYMODEL.options[fields[item.data]],
1632
1649
  value: item.search.value,
1633
1650
  operator: 'AND',
1651
+ type: astype,
1634
1652
  })
1635
1653
  }
1636
1654
  })
@@ -1688,6 +1706,15 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
1688
1706
  const body = req.body
1689
1707
  const fields = body.fields
1690
1708
  const select = Util.selectParser(fields, MYMODEL)
1709
+ const asDate = []
1710
+ for (let key in MYMODEL.widgets) {
1711
+ if (MYMODEL.widgets[key].name == 'datetime') {
1712
+ asDate.push(key)
1713
+ }
1714
+ if (MYMODEL.widgets[key].name == 'datepicker') {
1715
+ asDate.push(key)
1716
+ }
1717
+ }
1691
1718
  let whereArray = []
1692
1719
  const columns = body.columns
1693
1720
  if (MYMODEL.keys.includes('company_id')) {
@@ -1700,11 +1727,16 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
1700
1727
  }
1701
1728
  columns.forEach(function (item) {
1702
1729
  if (item.search.value) {
1730
+ let astype = 'text'
1731
+ if (asDate.includes(fields[item.data])) {
1732
+ astype = 'date'
1733
+ }
1703
1734
  whereArray.push({
1704
1735
  field: fields[item.data],
1705
1736
  option: MYMODEL.options[fields[item.data]],
1706
1737
  value: item.search.value,
1707
1738
  operator: 'AND',
1739
+ type: astype,
1708
1740
  })
1709
1741
  }
1710
1742
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.0.89",
3
+ "version": "1.0.91",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"