zet-lib 1.0.89 → 1.0.90
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 +15 -6
- package/lib/zRoute.js +32 -0
- package/package.json +1 -1
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",isJSON : false, type:"text,json,date"}]
|
|
52
52
|
const whereArray = obj.whereArray || []
|
|
53
53
|
let increment = 1
|
|
54
54
|
let arr = [],
|
|
@@ -61,11 +61,21 @@ const whereFn = (obj) => {
|
|
|
61
61
|
wherequery = arr.length ? wherequery.join(' AND ') : ''
|
|
62
62
|
if (whereArray.length) {
|
|
63
63
|
let andOr = wherequery ? ' AND ' : ''
|
|
64
|
-
whereArray.
|
|
65
|
-
|
|
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)
|
|
68
|
-
|
|
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) {
|
|
@@ -79,7 +89,6 @@ const whereFn = (obj) => {
|
|
|
79
89
|
} else {
|
|
80
90
|
wherequery += `${andOr} ${field} ${item.option} $${increment} ${operator}`
|
|
81
91
|
}
|
|
82
|
-
|
|
83
92
|
let itemValue = item.value
|
|
84
93
|
if (item.option == '=') {
|
|
85
94
|
itemValue = Util.replaceAll(itemValue, '%', '')
|
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
|
})
|