zet-lib 3.2.2 → 3.2.3

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/Model.js CHANGED
@@ -1,8 +1,3 @@
1
- /**
2
- * Universal class Model
3
- * Created by sintret dev on 9/23/2021.
4
- */
5
-
6
1
  const Util = require('./Util');
7
2
 
8
3
  /*
@@ -2389,6 +2384,7 @@ Model.relation = {
2389
2384
  "table",
2390
2385
  "name",
2391
2386
  "concat",
2387
+ "where",
2392
2388
  "please_select",
2393
2389
  "isChain",
2394
2390
  "isAttributes",
@@ -2407,6 +2403,7 @@ Model.relation = {
2407
2403
  table: "Module Name",
2408
2404
  name: "Label",
2409
2405
  concat: "Concat",
2406
+ where: "Where SQL",
2410
2407
  isChain: "is Chain",
2411
2408
  isAttributes: "With Attributes",
2412
2409
  information: "Additional Information",
@@ -2425,6 +2422,7 @@ Model.relation = {
2425
2422
  table: "user",
2426
2423
  name: "username",
2427
2424
  concat: "CONCAT(fullname, ' ',email)",
2425
+ where:"",
2428
2426
  isChain: false,
2429
2427
  isAttributes: false,
2430
2428
  information: "",
@@ -2461,6 +2459,10 @@ Model.relation = {
2461
2459
  tag: "input",
2462
2460
  type: "text",
2463
2461
  },
2462
+ where: {
2463
+ tag: "input",
2464
+ type: "text",
2465
+ },
2464
2466
  isChain: {
2465
2467
  tag: "input",
2466
2468
  type: "checkbox",
@@ -2542,6 +2544,7 @@ Model.typeahead = {
2542
2544
  "table",
2543
2545
  "name",
2544
2546
  "concat",
2547
+ "where",
2545
2548
  "information",
2546
2549
  "order_by",
2547
2550
  "import_field",
@@ -2553,6 +2556,7 @@ Model.typeahead = {
2553
2556
  table: "Module Name",
2554
2557
  name: "Label",
2555
2558
  concat: "Concat",
2559
+ where:"Where SQL",
2556
2560
  information: "Additional Information",
2557
2561
  order_by : "Order By",
2558
2562
  import_field :"Default Import Field (id)",
@@ -2563,6 +2567,7 @@ Model.typeahead = {
2563
2567
  tabindex: 1,
2564
2568
  table: "user",
2565
2569
  concat: "CONCAT(fullname, ' ',email)",
2570
+ where:"",
2566
2571
  information: "",
2567
2572
  order_by : "",
2568
2573
  import_field :"id"
@@ -2592,6 +2597,10 @@ Model.typeahead = {
2592
2597
  tag: "input",
2593
2598
  type: "text",
2594
2599
  },
2600
+ where: {
2601
+ tag: "input",
2602
+ type: "text",
2603
+ },
2595
2604
  information: {
2596
2605
  tag: "input",
2597
2606
  type: "text",
@@ -2702,6 +2711,7 @@ Model.dropdown_multi = {
2702
2711
  "table",
2703
2712
  "name",
2704
2713
  "concat",
2714
+ "where",
2705
2715
  "information",
2706
2716
  "order_by",
2707
2717
  "import_field",
@@ -2713,6 +2723,7 @@ Model.dropdown_multi = {
2713
2723
  table: "Module Name",
2714
2724
  name: "Name",
2715
2725
  concat: "Concat",
2726
+ where: "Where SQL",
2716
2727
  information: "Additional Information",
2717
2728
  order_by : "Order By",
2718
2729
  import_field :"Default Import Field (id)",
@@ -2724,6 +2735,7 @@ Model.dropdown_multi = {
2724
2735
  table: "user",
2725
2736
  name: "username",
2726
2737
  concat: "CONCAT(fullname, ' ',email)",
2738
+ where: "",
2727
2739
  information: "",
2728
2740
  order_by : "",
2729
2741
  import_field :"id"
@@ -2753,6 +2765,10 @@ Model.dropdown_multi = {
2753
2765
  tag: "input",
2754
2766
  type: "text",
2755
2767
  },
2768
+ where: {
2769
+ tag: "input",
2770
+ type: "text",
2771
+ },
2756
2772
  information: {
2757
2773
  tag: "input",
2758
2774
  type: "text",
@@ -333,6 +333,10 @@ me.prepare = (MYMODEL) => {
333
333
  if (Object.prototype.hasOwnProperty.call(property.values, "readonly")) {
334
334
  widgets[key].readonly = property.values.readonly ? true : false;
335
335
  }
336
+ if (Object.prototype.hasOwnProperty.call(property.values, "where")) {
337
+ widgets[key].where = property.values.where || "";
338
+ console.log(widgets[key].where)
339
+ }
336
340
 
337
341
  switch (type) {
338
342
  case "image":
@@ -342,6 +342,8 @@ router.post("/save_and_generate", csrfProtection, async (req, res) => {
342
342
  if (nots.includes(req.body.table)) {
343
343
  return res.json(Util.flashError("Table is locked"));
344
344
  }
345
+ let dir = `${dirRoot}/public/temp`
346
+ Util.dirExist(dir, true);
345
347
  //console.log(JSON.stringify(req.body))
346
348
  const json = await generate(req, res);
347
349
  res.json(json);
package/lib/zRoute.js CHANGED
@@ -5880,6 +5880,7 @@ cache models in so it's no need call database repeatly
5880
5880
  zRoute.modelsCache = async () => {
5881
5881
  let obj = {};
5882
5882
  let orderBy = {};
5883
+ let whereKeys = {}
5883
5884
  let dragdropsObj = {};
5884
5885
  if (process.env.APP_IS_CACHE == 1) {
5885
5886
  let models = zRoute.MYMODELS() || {};
@@ -5903,18 +5904,35 @@ zRoute.modelsCache = async () => {
5903
5904
  obj[table] = {};
5904
5905
  }
5905
5906
  if (!Util.in_array(key, nots)) {
5906
- obj[table][
5907
- `${keys}___${key}`
5908
- ] = `${widgets[key].fields[1]} as ${key}_${models[keys].table}`;
5909
- if (
5910
- Object.prototype.hasOwnProperty.call(models[keys].widgets, key)
5911
- ) {
5912
- if (
5913
- Object.prototype.hasOwnProperty.call(
5914
- models[keys].widgets[key],
5915
- "order_by"
5916
- )
5917
- ) {
5907
+ obj[table][`${keys}___${key}`] = `${widgets[key].fields[1]} as ${key}_${models[keys].table}`;
5908
+ if (widgets[key].where) {
5909
+ if (!whereKeys[table]) {
5910
+ whereKeys[table] = {};
5911
+ }
5912
+ let whereWidget = (widgets[key].where || "").trim();
5913
+ if (whereWidget) {
5914
+ let whereObj = {};
5915
+ if (whereWidget.includes(",")) {
5916
+ let splits = whereWidget.split(",");
5917
+ splits.forEach((item) => {
5918
+ let parts = item.trim().split("=");
5919
+ if (parts.length >= 2) {
5920
+ whereObj[parts[0].trim()] = parts.slice(1).join("=").trim();
5921
+ }
5922
+ });
5923
+ } else {
5924
+ let parts = whereWidget.split("=");
5925
+ if (parts.length >= 2) {
5926
+ whereObj[parts[0].trim()] = parts.slice(1).join("=").trim();
5927
+ }
5928
+ }
5929
+ if (Object.keys(whereObj).length) {
5930
+ whereKeys[table][`${keys}___${key}`] = whereObj;
5931
+ }
5932
+ }
5933
+ }
5934
+ if (Object.prototype.hasOwnProperty.call(models[keys].widgets, key)) {
5935
+ if (Object.prototype.hasOwnProperty.call(models[keys].widgets[key],"order_by")) {
5918
5936
  if (models[keys].widgets[key].order_by) {
5919
5937
  orderBy[table] = models[keys].widgets[key].order_by;
5920
5938
  }
@@ -5944,27 +5962,67 @@ zRoute.modelsCache = async () => {
5944
5962
  );
5945
5963
  if (checks[0].oke) {
5946
5964
  if (!Util.in_array(keys, zRoute.tableHasNoCompanyId)) {
5947
- let selects = ``;
5965
+ let keysWithoutWhere = [];
5966
+ let keysWithWhere = [];
5948
5967
  for (let key in obj[keys]) {
5949
- selects += `${obj[keys][key]},`;
5968
+ if (whereKeys[keys] && whereKeys[keys][key]) {
5969
+ keysWithWhere.push(key);
5970
+ } else {
5971
+ keysWithoutWhere.push(key);
5972
+ }
5950
5973
  }
5951
- selects += `id, company_id`;
5952
5974
  for (const company of companies) {
5953
- //console.log('selects : '+ selects + ' table : '+keys + ' ')
5954
- let objectSQL = {
5955
- table: keys,
5956
- select: selects,
5957
- where: {
5958
- company_id: company.id,
5959
- },
5960
- };
5961
- //console.log(keys)
5962
- if (orderBy[keys]) {
5963
- objectSQL.order_by = [`${orderBy[keys]}`];
5975
+ let wheres = {};
5976
+ wheres['company_id'] = company.id;
5977
+ if (keysWithoutWhere.length > 0) {
5978
+ let selects = ``;
5979
+ for (let key of keysWithoutWhere) {
5980
+ selects += `${obj[keys][key]},`;
5981
+ }
5982
+ selects += `id, company_id`;
5983
+ let objectSQL = {
5984
+ table: keys,
5985
+ select: selects,
5986
+ where: wheres,
5987
+ };
5988
+ if (orderBy[keys]) {
5989
+ objectSQL.order_by = [`${orderBy[keys]}`];
5990
+ }
5991
+ const results = await connection.results(objectSQL);
5992
+ for (let key of keysWithoutWhere) {
5993
+ const splits = key.split("___") || [];
5994
+ let item = splits.length > 1 ? splits[1] : key;
5995
+ let arr = [];
5996
+ for (const result of results) {
5997
+ if (result[`${item}_${splits[0]}`]) {
5998
+ arr.push({
5999
+ id: result.id,
6000
+ zname: result[`${item}_${splits[0]}`],
6001
+ });
6002
+ } else {
6003
+ arr.push({ id: result.id, zname: result[item] });
6004
+ }
6005
+ }
6006
+ if (orderBy[keys]) {
6007
+ myCache.set(`${keys}_${key}_${company.id}`, arr);
6008
+ } else {
6009
+ const myarray = Util.sortArray(arr, "zname");
6010
+ myCache.set(`${keys}_${key}_${company.id}`, myarray);
6011
+ }
6012
+ }
5964
6013
  }
5965
- const results = await connection.results(objectSQL);
5966
- for (let key in obj[keys]) {
5967
- //console.log('key : '+ key + ' obj[keys] : '+ JSON.stringify(obj[keys]) + ' ')
6014
+ for (let key of keysWithWhere) {
6015
+ let whereMerge = { ...wheres, ...whereKeys[keys][key] };
6016
+ let selectOne = `${obj[keys][key]}`;
6017
+ let objectSQL = {
6018
+ table: keys,
6019
+ select: `${selectOne}, id, company_id`,
6020
+ where: whereMerge,
6021
+ };
6022
+ if (orderBy[keys]) {
6023
+ objectSQL.order_by = [`${orderBy[keys]}`];
6024
+ }
6025
+ const results = await connection.results(objectSQL);
5968
6026
  const splits = key.split("___") || [];
5969
6027
  let item = splits.length > 1 ? splits[1] : key;
5970
6028
  let arr = [];
@@ -5982,7 +6040,6 @@ zRoute.modelsCache = async () => {
5982
6040
  myCache.set(`${keys}_${key}_${company.id}`, arr);
5983
6041
  } else {
5984
6042
  const myarray = Util.sortArray(arr, "zname");
5985
- //console.log(`${keys}_${key}_${company.id}`)
5986
6043
  myCache.set(`${keys}_${key}_${company.id}`, myarray);
5987
6044
  }
5988
6045
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"