zet-lib 1.3.28 → 1.3.30
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 +21 -0
- package/lib/zGeneratorRouter.js +1 -1
- package/lib/zRoute.js +40 -41
- package/package.json +1 -1
package/lib/connection.js
CHANGED
|
@@ -179,6 +179,27 @@ connection.results = async (obj) => {
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
connection.sql = async (obj) => {
|
|
183
|
+
const select = obj.select || '*'
|
|
184
|
+
const table = obj.table || ''
|
|
185
|
+
//[{field:"your_field",option:"=>",value:"12",operator:"AND",type:"text,json,date"}]
|
|
186
|
+
const statement = obj.statement || ''
|
|
187
|
+
const limit = obj.limit ? ` LIMIT ${obj.limit} ` : ''
|
|
188
|
+
const offset = obj.hasOwnProperty('offset') ? ` OFFSET ${obj.offset} ` : obj.limit ? 'OFFSET 0' : ''
|
|
189
|
+
const orderBy = orderByFn(obj)
|
|
190
|
+
const values = obj.values || []
|
|
191
|
+
const objJoin = obj.joins || []
|
|
192
|
+
let join = ''
|
|
193
|
+
if (objJoin.length) {
|
|
194
|
+
join = objJoin.join(' ')
|
|
195
|
+
}
|
|
196
|
+
const whereObj = whereFn(obj)
|
|
197
|
+
const wheres = whereObj.where
|
|
198
|
+
const arr = whereObj.arr
|
|
199
|
+
const sql = `SELECT ${select} FROM "${table}" ${join} ${wheres} ${statement} ${orderBy} ${limit} ${offset}`
|
|
200
|
+
return { sql: sql, arr: arr }
|
|
201
|
+
}
|
|
202
|
+
|
|
182
203
|
connection.result = async (obj) => {
|
|
183
204
|
const results = await connection.results(obj)
|
|
184
205
|
if (results.length) {
|
package/lib/zGeneratorRouter.js
CHANGED
|
@@ -682,7 +682,7 @@ const buildJoin = async (MYMODEL, result) => {
|
|
|
682
682
|
console.log(originKey)
|
|
683
683
|
newDataObj[item.key] = item.value
|
|
684
684
|
MYMODEL.keys.push(item.key)
|
|
685
|
-
MYMODEL.keysExcel.push(item.key)
|
|
685
|
+
//MYMODEL.keysExcel.push(item.key)
|
|
686
686
|
MYMODEL.labels[item.key] = item.value
|
|
687
687
|
MYMODEL.fields[item.key] = THEIR_MODEL.fields[originKey]
|
|
688
688
|
MYMODEL.options[item.key] = THEIR_MODEL.options[originKey]
|
package/lib/zRoute.js
CHANGED
|
@@ -880,6 +880,15 @@ zRoute.dataTableFilter = (MYMODEL, relations, filter) => {
|
|
|
880
880
|
types[key] = 'select'
|
|
881
881
|
break
|
|
882
882
|
|
|
883
|
+
case 'dropdown_checkbox':
|
|
884
|
+
options = MYMODEL.widgets[key].fields.reduce((result, item) => {
|
|
885
|
+
var selected = value == item ? ' selected ' : ''
|
|
886
|
+
return result + `<option value="${item}" ${selected} >${item}</option>`
|
|
887
|
+
}, '')
|
|
888
|
+
dataTable[key] = `<select id="data_table_${key}" class="form-control form-select search"><option value=""></option>${options}</select>`
|
|
889
|
+
types[key] = 'select'
|
|
890
|
+
break
|
|
891
|
+
|
|
883
892
|
case 'dropdown_multi':
|
|
884
893
|
options = relations[key].reduce((result, item) => {
|
|
885
894
|
var selected = value == item.id ? ' selected ' : ''
|
|
@@ -1437,12 +1446,14 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
|
|
|
1437
1446
|
})
|
|
1438
1447
|
let rows = []
|
|
1439
1448
|
let fields = []
|
|
1449
|
+
let fieldNames = []
|
|
1440
1450
|
let body = {}
|
|
1441
1451
|
let select = ''
|
|
1442
1452
|
let arr = []
|
|
1443
1453
|
let allfields = Object.keys(MYMODEL.widgets)
|
|
1444
1454
|
if (results.length) {
|
|
1445
1455
|
let result = results[0]
|
|
1456
|
+
fieldNames = result.filter.fields
|
|
1446
1457
|
body = result.filter
|
|
1447
1458
|
fields = body.fields.filter((item) => item != 'no' && item != 'actionColumn')
|
|
1448
1459
|
select = Util.selectParser(fields, MYMODEL)
|
|
@@ -1468,23 +1479,22 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
|
|
|
1468
1479
|
value: res.locals.companyId,
|
|
1469
1480
|
operator: 'AND',
|
|
1470
1481
|
})
|
|
1471
|
-
|
|
1472
1482
|
let columns = body.columns
|
|
1473
1483
|
columns.forEach(function (item) {
|
|
1474
|
-
if (item.search.value) {
|
|
1484
|
+
if (item.search.value != '') {
|
|
1475
1485
|
let astype = 'text'
|
|
1476
|
-
if (asDate.includes(
|
|
1486
|
+
if (asDate.includes(fieldNames[item.data])) {
|
|
1477
1487
|
astype = 'date'
|
|
1478
1488
|
}
|
|
1479
|
-
if (asJSONb.includes(
|
|
1489
|
+
if (asJSONb.includes(fieldNames[item.data])) {
|
|
1480
1490
|
astype = 'jsonb'
|
|
1481
1491
|
}
|
|
1482
|
-
if (asArray.includes(
|
|
1492
|
+
if (asArray.includes(fieldNames[item.data])) {
|
|
1483
1493
|
astype = 'array'
|
|
1484
1494
|
}
|
|
1485
1495
|
if (astype === 'jsonb') {
|
|
1486
1496
|
whereArray.push({
|
|
1487
|
-
field: Util.fieldWithTable(
|
|
1497
|
+
field: Util.fieldWithTable(fieldNames[item.data], MYMODEL, true),
|
|
1488
1498
|
option: ' ',
|
|
1489
1499
|
value: ` @> '["${item.search.value}"]'`,
|
|
1490
1500
|
operator: 'AND',
|
|
@@ -1494,14 +1504,14 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
|
|
|
1494
1504
|
whereArray.push({
|
|
1495
1505
|
field: '',
|
|
1496
1506
|
option: '',
|
|
1497
|
-
value: ` ${Util.fieldWithTable(
|
|
1507
|
+
value: ` ${Util.fieldWithTable(fieldNames[item.data], MYMODEL, true)}::text ILIKE '${item.search.value}' `,
|
|
1498
1508
|
operator: 'AND',
|
|
1499
1509
|
type: 'inline',
|
|
1500
1510
|
})
|
|
1501
1511
|
} else {
|
|
1502
1512
|
whereArray.push({
|
|
1503
|
-
field: Util.fieldWithTable(
|
|
1504
|
-
option: MYMODEL.options[
|
|
1513
|
+
field: Util.fieldWithTable(fieldNames[item.data], MYMODEL, true),
|
|
1514
|
+
option: MYMODEL.options[fieldNames[item.data]],
|
|
1505
1515
|
value: item.search.value,
|
|
1506
1516
|
operator: 'AND',
|
|
1507
1517
|
type: astype,
|
|
@@ -1509,8 +1519,7 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
|
|
|
1509
1519
|
}
|
|
1510
1520
|
}
|
|
1511
1521
|
})
|
|
1512
|
-
|
|
1513
|
-
const orderColumn = fields[body.order[0].column] == 'actionColumn' ? `${table}.id` : fields[body.order[0].column] == 'no' ? `${table}.id` : fields[body.order[0].column] == 'actionColum' ? `${table}.id` : fields[body.order[0].column]
|
|
1522
|
+
const orderColumn = fieldNames[body.order[0].column] == 'actionColumn' ? `${table}.id` : fieldNames[body.order[0].column] == 'no' ? `${table}.id` : fieldNames[body.order[0].column] == 'actionColum' ? `${table}.id` : fieldNames[body.order[0].column]
|
|
1514
1523
|
if (zstandart) {
|
|
1515
1524
|
select = Util.selectParser(allfields, MYMODEL)
|
|
1516
1525
|
}
|
|
@@ -1562,7 +1571,7 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
|
|
|
1562
1571
|
}
|
|
1563
1572
|
|
|
1564
1573
|
// for excels
|
|
1565
|
-
zRoute.excel = async (req, res, MYMODEL,
|
|
1574
|
+
zRoute.excel = async (req, res, MYMODEL, fields, rows, callback, fileName) => {
|
|
1566
1575
|
const cacheRole = myCache.get('ROLES')[res.locals.roleId].params
|
|
1567
1576
|
const levels = cacheRole[MYMODEL.table] || []
|
|
1568
1577
|
if (!levels.includes('export')) {
|
|
@@ -1574,12 +1583,6 @@ zRoute.excel = async (req, res, MYMODEL, myfields, rows, callback, fileName) =>
|
|
|
1574
1583
|
if (joins.length > 0) {
|
|
1575
1584
|
notJoins = MYMODEL.joins.list || []
|
|
1576
1585
|
}
|
|
1577
|
-
let fields = []
|
|
1578
|
-
myfields.map((item) => {
|
|
1579
|
-
if (!notJoins.includes(item)) {
|
|
1580
|
-
fields.push(item)
|
|
1581
|
-
}
|
|
1582
|
-
})
|
|
1583
1586
|
|
|
1584
1587
|
//if any other custom value then callback needed
|
|
1585
1588
|
callback = callback || function () {}
|
|
@@ -1656,23 +1659,23 @@ zRoute.excel = async (req, res, MYMODEL, myfields, rows, callback, fileName) =>
|
|
|
1656
1659
|
let usersObj = await zRoute.getUsers()
|
|
1657
1660
|
if (Object.prototype.hasOwnProperty.call(MYMODEL, 'widgets')) {
|
|
1658
1661
|
for (let key in MYMODEL.widgets) {
|
|
1659
|
-
if (!notJoins.includes(key)) {
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
}
|
|
1662
|
+
//if (!notJoins.includes(key)) {
|
|
1663
|
+
let widget = MYMODEL.widgets[key]
|
|
1664
|
+
if (widget.name == 'password') {
|
|
1665
|
+
passwords.push(key)
|
|
1666
|
+
} else if (widget.name == 'select') {
|
|
1667
|
+
tableObj[key] = widget.fields
|
|
1668
|
+
} else if (widget.name == 'switch') {
|
|
1669
|
+
tableObj[key] = widget.fields
|
|
1670
|
+
} else if (widget.name == 'relation' || widget.name == 'typeahead') {
|
|
1671
|
+
var rowsarr = await connection.results({
|
|
1672
|
+
table: widget.table,
|
|
1673
|
+
select: widget.fields[0] + ',' + widget.fields[1] + ' as zname ',
|
|
1674
|
+
})
|
|
1675
|
+
//save to object
|
|
1676
|
+
relations[key] = Util.arrayToObject(rowsarr, 'id')
|
|
1675
1677
|
}
|
|
1678
|
+
//}
|
|
1676
1679
|
}
|
|
1677
1680
|
}
|
|
1678
1681
|
|
|
@@ -2029,13 +2032,7 @@ zRoute.listDataTable = async (req, res, objData = {}) => {
|
|
|
2029
2032
|
if (MYMODEL.widgets[key].name == 'datepicker') {
|
|
2030
2033
|
asDate.push(key)
|
|
2031
2034
|
}
|
|
2032
|
-
if (MYMODEL.widgets[key].name == 'dropdown_multi') {
|
|
2033
|
-
asJSONb.push(key)
|
|
2034
|
-
}
|
|
2035
|
-
if (MYMODEL.widgets[key].name == 'dragdrop') {
|
|
2036
|
-
asJSONb.push(key)
|
|
2037
|
-
}
|
|
2038
|
-
if (MYMODEL.widgets[key].name == 'dropdown_checkbox') {
|
|
2035
|
+
if (MYMODEL.widgets[key].name == 'dropdown_multi' || MYMODEL.widgets[key].name == 'dragdrop' || MYMODEL.widgets[key].name == 'dropdown_checkbox') {
|
|
2039
2036
|
asJSONb.push(key)
|
|
2040
2037
|
}
|
|
2041
2038
|
if (MYMODEL.widgets[key].name == 'json_array' || MYMODEL.widgets[key].name == 'array' || MYMODEL.widgets[key].name == 'dropzone') {
|
|
@@ -2108,6 +2105,8 @@ zRoute.listDataTable = async (req, res, objData = {}) => {
|
|
|
2108
2105
|
gridData.joins = joins
|
|
2109
2106
|
}
|
|
2110
2107
|
const rows = await connection.results(gridData)
|
|
2108
|
+
//let sql = await connection.sql(gridData)
|
|
2109
|
+
//console.log(sql)
|
|
2111
2110
|
let gridCount = {
|
|
2112
2111
|
select: `count(${table}.id) as count`,
|
|
2113
2112
|
table: MYMODEL.table,
|