zet-lib 1.3.27 → 1.3.29
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 +74 -59
- 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
|
@@ -1437,12 +1437,14 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
|
|
|
1437
1437
|
})
|
|
1438
1438
|
let rows = []
|
|
1439
1439
|
let fields = []
|
|
1440
|
+
let fieldNames = []
|
|
1440
1441
|
let body = {}
|
|
1441
1442
|
let select = ''
|
|
1442
1443
|
let arr = []
|
|
1443
1444
|
let allfields = Object.keys(MYMODEL.widgets)
|
|
1444
1445
|
if (results.length) {
|
|
1445
1446
|
let result = results[0]
|
|
1447
|
+
fieldNames = result.filter.fields
|
|
1446
1448
|
body = result.filter
|
|
1447
1449
|
fields = body.fields.filter((item) => item != 'no' && item != 'actionColumn')
|
|
1448
1450
|
select = Util.selectParser(fields, MYMODEL)
|
|
@@ -1468,23 +1470,22 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
|
|
|
1468
1470
|
value: res.locals.companyId,
|
|
1469
1471
|
operator: 'AND',
|
|
1470
1472
|
})
|
|
1471
|
-
|
|
1472
1473
|
let columns = body.columns
|
|
1473
1474
|
columns.forEach(function (item) {
|
|
1474
|
-
if (item.search.value) {
|
|
1475
|
+
if (item.search.value != '') {
|
|
1475
1476
|
let astype = 'text'
|
|
1476
|
-
if (asDate.includes(
|
|
1477
|
+
if (asDate.includes(fieldNames[item.data])) {
|
|
1477
1478
|
astype = 'date'
|
|
1478
1479
|
}
|
|
1479
|
-
if (asJSONb.includes(
|
|
1480
|
+
if (asJSONb.includes(fieldNames[item.data])) {
|
|
1480
1481
|
astype = 'jsonb'
|
|
1481
1482
|
}
|
|
1482
|
-
if (asArray.includes(
|
|
1483
|
+
if (asArray.includes(fieldNames[item.data])) {
|
|
1483
1484
|
astype = 'array'
|
|
1484
1485
|
}
|
|
1485
1486
|
if (astype === 'jsonb') {
|
|
1486
1487
|
whereArray.push({
|
|
1487
|
-
field: Util.fieldWithTable(
|
|
1488
|
+
field: Util.fieldWithTable(fieldNames[item.data], MYMODEL, true),
|
|
1488
1489
|
option: ' ',
|
|
1489
1490
|
value: ` @> '["${item.search.value}"]'`,
|
|
1490
1491
|
operator: 'AND',
|
|
@@ -1494,14 +1495,14 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
|
|
|
1494
1495
|
whereArray.push({
|
|
1495
1496
|
field: '',
|
|
1496
1497
|
option: '',
|
|
1497
|
-
value: ` ${Util.fieldWithTable(
|
|
1498
|
+
value: ` ${Util.fieldWithTable(fieldNames[item.data], MYMODEL, true)}::text ILIKE '${item.search.value}' `,
|
|
1498
1499
|
operator: 'AND',
|
|
1499
1500
|
type: 'inline',
|
|
1500
1501
|
})
|
|
1501
1502
|
} else {
|
|
1502
1503
|
whereArray.push({
|
|
1503
|
-
field: Util.fieldWithTable(
|
|
1504
|
-
option: MYMODEL.options[
|
|
1504
|
+
field: Util.fieldWithTable(fieldNames[item.data], MYMODEL, true),
|
|
1505
|
+
option: MYMODEL.options[fieldNames[item.data]],
|
|
1505
1506
|
value: item.search.value,
|
|
1506
1507
|
operator: 'AND',
|
|
1507
1508
|
type: astype,
|
|
@@ -1509,8 +1510,7 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
|
|
|
1509
1510
|
}
|
|
1510
1511
|
}
|
|
1511
1512
|
})
|
|
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]
|
|
1513
|
+
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
1514
|
if (zstandart) {
|
|
1515
1515
|
select = Util.selectParser(allfields, MYMODEL)
|
|
1516
1516
|
}
|
|
@@ -1562,7 +1562,7 @@ zRoute.excelQuery = async (req, res, MYMODEL, paramsObject = {}) => {
|
|
|
1562
1562
|
}
|
|
1563
1563
|
|
|
1564
1564
|
// for excels
|
|
1565
|
-
zRoute.excel = async (req, res, MYMODEL,
|
|
1565
|
+
zRoute.excel = async (req, res, MYMODEL, fields, rows, callback, fileName) => {
|
|
1566
1566
|
const cacheRole = myCache.get('ROLES')[res.locals.roleId].params
|
|
1567
1567
|
const levels = cacheRole[MYMODEL.table] || []
|
|
1568
1568
|
if (!levels.includes('export')) {
|
|
@@ -1574,12 +1574,6 @@ zRoute.excel = async (req, res, MYMODEL, myfields, rows, callback, fileName) =>
|
|
|
1574
1574
|
if (joins.length > 0) {
|
|
1575
1575
|
notJoins = MYMODEL.joins.list || []
|
|
1576
1576
|
}
|
|
1577
|
-
let fields = []
|
|
1578
|
-
myfields.map((item) => {
|
|
1579
|
-
if (!notJoins.includes(item)) {
|
|
1580
|
-
fields.push(item)
|
|
1581
|
-
}
|
|
1582
|
-
})
|
|
1583
1577
|
|
|
1584
1578
|
//if any other custom value then callback needed
|
|
1585
1579
|
callback = callback || function () {}
|
|
@@ -1656,23 +1650,23 @@ zRoute.excel = async (req, res, MYMODEL, myfields, rows, callback, fileName) =>
|
|
|
1656
1650
|
let usersObj = await zRoute.getUsers()
|
|
1657
1651
|
if (Object.prototype.hasOwnProperty.call(MYMODEL, 'widgets')) {
|
|
1658
1652
|
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
|
-
}
|
|
1653
|
+
//if (!notJoins.includes(key)) {
|
|
1654
|
+
let widget = MYMODEL.widgets[key]
|
|
1655
|
+
if (widget.name == 'password') {
|
|
1656
|
+
passwords.push(key)
|
|
1657
|
+
} else if (widget.name == 'select') {
|
|
1658
|
+
tableObj[key] = widget.fields
|
|
1659
|
+
} else if (widget.name == 'switch') {
|
|
1660
|
+
tableObj[key] = widget.fields
|
|
1661
|
+
} else if (widget.name == 'relation' || widget.name == 'typeahead') {
|
|
1662
|
+
var rowsarr = await connection.results({
|
|
1663
|
+
table: widget.table,
|
|
1664
|
+
select: widget.fields[0] + ',' + widget.fields[1] + ' as zname ',
|
|
1665
|
+
})
|
|
1666
|
+
//save to object
|
|
1667
|
+
relations[key] = Util.arrayToObject(rowsarr, 'id')
|
|
1675
1668
|
}
|
|
1669
|
+
//}
|
|
1676
1670
|
}
|
|
1677
1671
|
}
|
|
1678
1672
|
|
|
@@ -4749,34 +4743,55 @@ module.exports = (req, res, next) => {`
|
|
|
4749
4743
|
}
|
|
4750
4744
|
|
|
4751
4745
|
zRoute.typeahead = async (req, res) => {
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4746
|
+
try {
|
|
4747
|
+
let table = req.params.table
|
|
4748
|
+
let keys = req.params.field
|
|
4749
|
+
const MYMODELS = myCache.get('MYMODELS')
|
|
4750
|
+
if (keys.includes('___')) {
|
|
4751
|
+
let split = keys.split('___')
|
|
4752
|
+
table = split[0]
|
|
4753
|
+
keys = split[1]
|
|
4754
|
+
}
|
|
4755
|
+
let MYMODEL = MYMODELS[table]
|
|
4756
|
+
let WIDGET = MYMODEL.widgets
|
|
4757
|
+
let query = {}
|
|
4758
|
+
//employee_payroll_salary___employee_id_1
|
|
4759
|
+
let name = `${MYMODEL.widgets[keys].table}_${MYMODEL.table}___${keys}_${res.locals.companyId}`
|
|
4760
|
+
let json = myCache.get(name)
|
|
4761
|
+
res.json(json)
|
|
4762
|
+
} catch (e) {
|
|
4763
|
+
console.log(e)
|
|
4764
|
+
res.json(e + '')
|
|
4765
|
+
}
|
|
4762
4766
|
}
|
|
4763
4767
|
|
|
4764
4768
|
zRoute.typeaheadpost = async (req, res) => {
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4769
|
+
try {
|
|
4770
|
+
let table = req.params.table
|
|
4771
|
+
let keys = req.params.field
|
|
4772
|
+
let id = req.body.id
|
|
4773
|
+
const MYMODELS = myCache.get('MYMODELS')
|
|
4774
|
+
if (keys.includes('___')) {
|
|
4775
|
+
let split = keys.split('___')
|
|
4776
|
+
table = split[0]
|
|
4777
|
+
keys = split[1]
|
|
4778
|
+
}
|
|
4779
|
+
let MYMODEL = MYMODELS[table]
|
|
4780
|
+
let WIDGET = MYMODEL.widgets
|
|
4781
|
+
let mytable = WIDGET[keys].table
|
|
4782
|
+
|
|
4783
|
+
let result = await connection.result({
|
|
4784
|
+
select: `${WIDGET[keys].fields[1]} as zname`,
|
|
4785
|
+
table: mytable,
|
|
4786
|
+
where: {
|
|
4787
|
+
id: id,
|
|
4788
|
+
},
|
|
4789
|
+
})
|
|
4790
|
+
res.json(result.zname)
|
|
4791
|
+
} catch (e) {
|
|
4792
|
+
console.log(e)
|
|
4793
|
+
res.json(e + '')
|
|
4794
|
+
}
|
|
4780
4795
|
}
|
|
4781
4796
|
|
|
4782
4797
|
zRoute.history = async (req, res, relations, id, MYMODEL, users, results = []) => {
|