@xuda.io/xuda-dbs-plugin-xuda 1.0.190 → 1.0.192

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/server.js +57 -1
  3. package/studio.mjs +7 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-dbs-plugin-xuda",
3
- "version": "1.0.190",
3
+ "version": "1.0.192",
4
4
  "description": "Xuda Database Socket for Xuda's proprietary structure powered by CouchDB",
5
5
  "scripts": {
6
6
  "pub": "npm version patch --force && npm publish --access public"
package/server.js CHANGED
@@ -254,7 +254,19 @@ const get_opt = function (e, table_obj) {
254
254
  opt.sort = sort;
255
255
  }
256
256
 
257
- if (e?.sortModel?.length) {
257
+ // if (e?.sortModel?.length) {
258
+ // opt.sort = JSON.parse(e.sortModel);
259
+ // if (opt.sort) {
260
+ // for (const [key, val] of Object.entries(opt.sort)) {
261
+ // var field_name = val.colId;
262
+ // opt.sort[key] = {
263
+ // ["udfData.data." + field_name]: val.sort,
264
+ // };
265
+ // }
266
+ // }
267
+ // }
268
+
269
+ if (e?.sortModel && JSON.parse(e.sortModel).length) {
258
270
  opt.sort = JSON.parse(e.sortModel);
259
271
  if (opt.sort) {
260
272
  for (const [key, val] of Object.entries(opt.sort)) {
@@ -478,6 +490,50 @@ const get_opt = function (e, table_obj) {
478
490
 
479
491
  var selector_new = {};
480
492
 
493
+ function replaceKeysInQuery(query) {
494
+ const keys_to_replace = table_obj.tableFields.map((e) => {
495
+ return e.id;
496
+ });
497
+
498
+ // Helper function to recursively process the query object
499
+ function recursiveReplace(obj) {
500
+ if (typeof obj === "object" && obj !== null) {
501
+ // Create a new object to store the modified query
502
+ let newObj = Array.isArray(obj) ? [] : {};
503
+
504
+ // Traverse through the object
505
+ for (let key in obj) {
506
+ if (obj.hasOwnProperty(key)) {
507
+ // If the key is in the keys_to_replace array, replace it
508
+ let newKey = keys_to_replace.includes(key)
509
+ ? `udfData.data.${key}`
510
+ : key;
511
+
512
+ // Recursively process nested objects
513
+ newObj[newKey] = recursiveReplace(obj[key]);
514
+ }
515
+ }
516
+
517
+ return newObj;
518
+ } else {
519
+ // If it's not an object or array, return the value as is
520
+ return obj;
521
+ }
522
+ }
523
+
524
+ // Start the recursive replacement
525
+ return recursiveReplace(query);
526
+ }
527
+
528
+ if (e.filterModelMongo) {
529
+ selector_new["$and"] = [replaceKeysInQuery(e.filterModelMongo)];
530
+ }
531
+ if (e.filterModelUserMongo) {
532
+ if (!selector_new["$and"]) {
533
+ selector_new["$and"] = [];
534
+ }
535
+ selector_new["$and"] = [replaceKeysInQuery(e.filterModelUserMongo)];
536
+ }
481
537
  for (const [key, val] of Object.entries(opt.selector)) {
482
538
  selector_new["udfData.data." + key] = val;
483
539
  }
package/studio.mjs CHANGED
@@ -509,13 +509,13 @@ const get_opt = function (e, table_obj) {
509
509
 
510
510
  var selector_new = {};
511
511
 
512
- for (const [key, val] of Object.entries(opt.selector)) {
513
- if (key.substring(0, 1) === "$") {
514
- selector_new[key] = val;
515
- continue;
516
- }
517
- selector_new["udfData.data." + key] = val;
518
- }
512
+ // for (const [key, val] of Object.entries(opt.selector)) {
513
+ // if (key.substring(0, 1) === "$") {
514
+ // selector_new[key] = val;
515
+ // continue;
516
+ // }
517
+ // selector_new["udfData.data." + key] = val;
518
+ // }
519
519
 
520
520
  // if (e.viewDbQuery) {
521
521
  // for (const [key, val] of Object.entries(table_obj.tableFields)) {