zet-lib 1.3.28 → 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 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) {
@@ -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(fields[item.data])) {
1477
+ if (asDate.includes(fieldNames[item.data])) {
1477
1478
  astype = 'date'
1478
1479
  }
1479
- if (asJSONb.includes(fields[item.data])) {
1480
+ if (asJSONb.includes(fieldNames[item.data])) {
1480
1481
  astype = 'jsonb'
1481
1482
  }
1482
- if (asArray.includes(fields[item.data])) {
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(fields[item.data], MYMODEL, true),
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(fields[item.data], MYMODEL, true)}::text ILIKE '${item.search.value}' `,
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(fields[item.data], MYMODEL, true),
1504
- option: MYMODEL.options[fields[item.data]],
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, myfields, rows, callback, fileName) => {
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
- let widget = MYMODEL.widgets[key]
1661
- if (widget.name == 'password') {
1662
- passwords.push(key)
1663
- } else if (widget.name == 'select') {
1664
- tableObj[key] = widget.fields
1665
- } else if (widget.name == 'switch') {
1666
- tableObj[key] = widget.fields
1667
- } else if (widget.name == 'relation' || widget.name == 'typeahead') {
1668
- var rowsarr = await connection.results({
1669
- table: widget.table,
1670
- select: widget.fields[0] + ',' + widget.fields[1] + ' as zname ',
1671
- })
1672
- //save to object
1673
- relations[key] = Util.arrayToObject(rowsarr, 'id')
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.3.28",
3
+ "version": "1.3.29",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"