@izara_project/izara-shared-search-and-sort 1.0.8 → 1.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-shared-search-and-sort",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Shared Libraries frontend/backend for Search and Sort stack",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,29 +22,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22
22
  // let { pattern } = validatorSchema.stringNotEmpty();
23
23
  // export default [...]
24
24
 
25
- import { objectHash as hash } from '@izara_project/izara-shared-core'; //const hash = require('@izara_project/izara-shared-core').objectHash;
25
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
26
26
  import lodash from 'lodash';
27
27
  const { isEmpty } = lodash;
28
- import filtersSharedLib from './FiltersSharedLib.js'; //const filtersSharedLib = require('./FiltersSharedLib');
28
+ import filtersSharedLib from './FiltersSharedLib.js';
29
+ import LogicalStructureSharedLib from './LogicalStructureSharedLib.js'
29
30
 
30
31
  async function createRequiredData(
31
32
  objType,
33
+ initialLogicalElementId,
34
+ logicalElements,
32
35
  requiredDataFields,
33
36
  complexFilterCombinations,
34
37
  perParentCombinations,
35
38
  requiredDataLinkStepObjects,
36
39
  requiredDataLinkSteps,
37
40
  values,
38
- getSchemaFn
39
41
  ) {
40
42
  console.log('createRequiredData: ', {
41
43
  objType,
44
+ initialLogicalElementId,
45
+ logicalElements,
42
46
  requiredDataFields,
43
47
  complexFilterCombinations,
44
48
  perParentCombinations,
45
49
  requiredDataLinkStepObjects,
50
+ requiredDataLinkSteps,
46
51
  values,
47
- getSchemaFn
48
52
  });
49
53
 
50
54
  let errorsObject = {};
@@ -69,12 +73,19 @@ async function createRequiredData(
69
73
  console.log('initial data: ', { linkSteps });
70
74
 
71
75
  let [fieldName, returnValue, linkPathErrorObject, linkPathErrorsFound] = await createLinkPath(
76
+ objType,
72
77
  linkSteps,
73
78
  requiredDataLinkStepObjects,
74
79
  requiredDataLinkSteps,
75
80
  perParentCombinations,
76
81
  complexFilterCombinations,
77
82
  values,
83
+ {
84
+ objType: objType,
85
+ initialLogicalElementId: initialLogicalElementId,
86
+ logicalElements: logicalElements
87
+ },
88
+ [],
78
89
  errorsObject,
79
90
  errorsFound
80
91
  );
@@ -129,15 +140,6 @@ async function createRequiredData(
129
140
  linkPathObjectId: pathId
130
141
  };
131
142
 
132
- let requiredFieldNameObject = {
133
- // fieldName: fieldName,
134
- fieldName: setObject,
135
- linkPathObjects: {
136
- [pathId]: pathObject
137
- },
138
- linkPathSteps: returnValue.linkStepObjects
139
- };
140
-
141
143
  if (returnValue.hasOwnProperty('complexFilterCombinations')) {
142
144
  // requiredFieldNameObject.complexFilterCombinations = returnValue.complexFilterCombinations;
143
145
  Object.assign(setComplexFilterCombinations, returnValue.complexFilterCombinations);
@@ -150,6 +152,15 @@ async function createRequiredData(
150
152
  };
151
153
  };
152
154
 
155
+ let requiredFieldNameObject = {
156
+ // fieldName: fieldName,
157
+ fieldName: setObject,
158
+ linkPathObjects: {
159
+ [pathId]: pathObject
160
+ },
161
+ linkPathSteps: returnValue.linkStepObjects
162
+ };
163
+
153
164
  if (returnValue.hasOwnProperty('perParentCombinations')) {
154
165
  // requiredFieldNameObject.perParentCombinations = returnValue.perParentCombinations;
155
166
  Object.assign(setPerParentCombinations, returnValue.perParentCombinations);
@@ -179,7 +190,12 @@ async function createRequiredData(
179
190
  console.log("------- requiredData has only fieldName ---------");
180
191
 
181
192
  let requiredFieldNameObject = {
182
- fieldName: fieldName
193
+ fieldName: {
194
+ fieldName: fieldName
195
+ },
196
+ //* don hash
197
+ linkPathObjects: {},
198
+ linkPathSteps: {}
183
199
  };
184
200
  console.log("requiredFieldNameObject: ", requiredFieldNameObject);
185
201
 
@@ -264,12 +280,15 @@ async function createRequiredData(
264
280
 
265
281
 
266
282
  async function createLinkPath(
283
+ objType,
267
284
  linkSteps,
268
285
  requiredDataLinkStepObjects,
269
286
  requiredDataLinkSteps,
270
287
  perParentCombinations,
271
288
  complexFilterCombinations,
272
289
  values,
290
+ filtersStructure,
291
+ path,
273
292
  errorsObject,
274
293
  errorsFound,
275
294
  index = 0,
@@ -283,6 +302,8 @@ async function createLinkPath(
283
302
  perParentCombinations,
284
303
  complexFilterCombinations,
285
304
  values,
305
+ filtersStructure,
306
+ path,
286
307
  errorsObject,
287
308
  errorsFound,
288
309
  index,
@@ -292,6 +313,8 @@ async function createLinkPath(
292
313
  let fieldName = null;
293
314
  let returnValue = {}; //* must return only linkPath params
294
315
 
316
+ let sortObj = null;
317
+
295
318
  let linkStepId = linkSteps[index];
296
319
  console.log('linkStepId: ', linkStepId);
297
320
 
@@ -302,33 +325,63 @@ async function createLinkPath(
302
325
  // last link that has only fieldName
303
326
  console.log('---------- is final link ----------', { index, linkStep });
304
327
 
305
- return [linkStep.fieldName, returnValue, errorsObject, errorsFound]
328
+ let sortValueObj = null;
329
+
330
+ if (linkStep.hasOwnProperty("dataType")) {
331
+
332
+ sortValueObj = {
333
+ dataType: linkStep.dataType,
334
+ value: linkStep.value
335
+ }
336
+
337
+ }
338
+
339
+ return [linkStep.fieldName, returnValue, errorsObject, errorsFound, sortValueObj]
306
340
 
307
341
  } else {
308
342
  // has nextLink
309
343
  console.log('---------- is next link ----------', { index, linkStep });
310
344
 
345
+ if (linkStep.hasOwnProperty("pathLinkType")) {
346
+ path.push({
347
+ objType: objType,
348
+ pathLinkType: linkStep.pathLinkType
349
+ });
350
+ console.log("path", path);
351
+ // console.log('---------- is next link ----------', hhhh);
352
+ }
353
+
311
354
  let conditionsPromise = checkConditionsLink(
312
- // let [conditions, conditionErrObject, conditionErrFound] = await this.checkConditionsLink(
355
+ // let [conditions, conditionErrObject, conditionErrFound] = await checkConditionsLink(
313
356
  linkStep.pathLinkType.objType,
314
357
  linkStep,
315
358
  perParentCombinations,
316
359
  complexFilterCombinations,
317
360
  values,
361
+ filtersStructure,
318
362
  linkSteps,
319
363
  requiredDataLinkStepObjects,
320
364
  requiredDataLinkSteps,
365
+ path,
321
366
  errorsObject,
322
367
  errorsFound
323
368
  );
369
+ // console.log('checkConditionsLink in link', {
370
+ // conditions,
371
+ // conditionErrObject,
372
+ // conditionErrFound
373
+ // });
324
374
 
325
- [fieldName, returnValue, errorsObject, errorsFound] = await createLinkPath(
375
+ [fieldName, returnValue, errorsObject, errorsFound, sortObj] = await createLinkPath(
376
+ linkStep.pathLinkType.objType,
326
377
  linkSteps,
327
378
  requiredDataLinkStepObjects,
328
379
  requiredDataLinkSteps,
329
380
  perParentCombinations,
330
381
  complexFilterCombinations,
331
382
  values,
383
+ filtersStructure,
384
+ path,
332
385
  errorsObject,
333
386
  errorsFound,
334
387
  index + 1
@@ -596,7 +649,7 @@ async function createLinkPath(
596
649
  console.log('returnValue', returnValue);
597
650
  }
598
651
  }
599
- return [fieldName, returnValue, errorsObject, errorsFound]
652
+ return [fieldName, returnValue, errorsObject, errorsFound, sortObj]
600
653
  }
601
654
 
602
655
 
@@ -606,9 +659,11 @@ async function checkConditionsLink(
606
659
  perParentCombinations,
607
660
  complexFilterCombinations,
608
661
  values,
662
+ filtersStructure,
609
663
  linkSteps,
610
664
  requiredDataLinkStepObjects,
611
665
  requiredDataLinkSteps,
666
+ path,
612
667
  errorsObject,
613
668
  errorsFound
614
669
  ) {
@@ -618,23 +673,76 @@ async function checkConditionsLink(
618
673
  perParentCombinations,
619
674
  complexFilterCombinations,
620
675
  values,
676
+ filtersStructure,
621
677
  linkSteps,
622
678
  requiredDataLinkStepObjects,
623
679
  requiredDataLinkSteps,
680
+ path,
624
681
  errorsObject,
625
682
  errorsFound
626
683
  });
627
684
 
628
685
 
629
- let conditionLinkObject = {}
686
+ let conditionLinkObject = {};
687
+ let filterMainRequest = null
688
+
689
+ if (linkStepObject.hasOwnProperty("addFilterMain") && linkStepObject.addFilterMain === true) {
690
+
691
+ path.push({ objType: objType });
692
+ console.log('path', path);
693
+
694
+ let [filterStructureCurrent, filterErrorObject, filterErrorFound] = await LogicalStructureSharedLib.changeObjTypePath(
695
+ objType,
696
+ filtersStructure,
697
+ path
698
+ );
699
+
700
+ console.log('changeObjTypePath', {
701
+ filterStructureCurrent,
702
+ filterErrorObject,
703
+ filterErrorFound
704
+ });
705
+
706
+ if (filterErrorFound.length > 0) {
707
+ Object.assign(errorsObject, filterErrorObject);
708
+ errorsFound = errorsFound.concat('filterErrorFound');
709
+ } else {
710
+ filterMainRequest = filterStructureCurrent;
711
+ }
712
+
713
+ }
630
714
 
631
715
  if (linkStepObject.hasOwnProperty('filterElements')) {
632
716
  console.log('------------ has filterElements ------------');
633
717
 
718
+ let filters = {};
719
+
720
+ if (filterMainRequest !== null) {
721
+ if (hash(filterMainRequest.objType) !== hash(linkStepObject.filterElements.objType)) {
722
+ errorsObject[linkStepObject.filterElements.objType.objectType] = 'this linkStep has error when combine filterMain in link';
723
+ errorsFound.push(`${linkStepObject.filterElements.objType.objectType}: this linkStep has error when combine filterMain in link`);
724
+ return [null, errorsObject, errorsFound];
725
+ }
726
+
727
+ filters = filtersSharedLib.combineLogicalElements(
728
+ filterMainRequest,
729
+ linkStepObject.filterElements
730
+ );
731
+
732
+
733
+ } else {
734
+ filters = {
735
+ objType: linkStepObject.filterElements.objType,
736
+ initialLogicalElementId: linkStepObject.filterElements.initialLogicalElementId,
737
+ logicalElements: linkStepObject.filterElements.logicalElements,
738
+ }
739
+ }
740
+ console.log('filters: ', filters);
741
+
634
742
  let [complexFilterRequest, status, filterErrorsObject, filterErrorsFound] = filtersSharedLib.createFiltersRequest(
635
- linkStepObject.filterElements.objType,
636
- linkStepObject.filterElements.initialLogicalElementId,
637
- linkStepObject.filterElements.logicalElements,
743
+ filters.objType,
744
+ filters.initialLogicalElementId,
745
+ filters.logicalElements,
638
746
  values
639
747
  );
640
748
  console.log('return complexFilter for filterElements: ', {
@@ -646,13 +754,40 @@ async function checkConditionsLink(
646
754
 
647
755
  if (filterErrorsFound.length > 0) {
648
756
  Object.assign(errorsObject, filterErrorsObject)
649
- errorsFound = errorsFound.concat(filterErrorsFound);
650
- return [null, errorsObject, errorsFound]
757
+ errorsFound = errorsFound.concat(filterErrorsFound)
651
758
  };
759
+
652
760
  conditionLinkObject.filterElements = complexFilterRequest.filterElements;
653
761
  console.log('conditionLinkObject in condition link: ', conditionLinkObject);
762
+
654
763
  }
655
764
 
765
+
766
+ // if (linkStepObject.hasOwnProperty('filterElements')) {
767
+ // console.log('------------ has filterElements ------------');
768
+
769
+ // let [complexFilterRequest, status, filterErrorsObject, filterErrorsFound] = filtersSharedLib.createFiltersRequest(
770
+ // linkStepObject.filterElements.objType,
771
+ // linkStepObject.filterElements.initialLogicalElementId,
772
+ // linkStepObject.filterElements.logicalElements,
773
+ // values
774
+ // );
775
+ // console.log('return complexFilter for filterElements: ', {
776
+ // complexFilterRequest,
777
+ // status,
778
+ // filterErrorsObject,
779
+ // filterErrorsFound
780
+ // });
781
+
782
+ // if (filterErrorsFound.length > 0) {
783
+ // Object.assign(errorsObject, filterErrorsObject)
784
+ // errorsFound = errorsFound.concat(filterErrorsFound);
785
+ // return [null, errorsObject, errorsFound]
786
+ // };
787
+ // conditionLinkObject.filterElements = complexFilterRequest.filterElements;
788
+ // console.log('conditionLinkObject in condition link: ', conditionLinkObject);
789
+ // }
790
+
656
791
  if (linkStepObject.hasOwnProperty('aggregate')) {
657
792
  console.log('------------ has aggregate ------------');
658
793
  if (!linkStepObject.hasOwnProperty('sortFields')) {
@@ -683,19 +818,25 @@ async function checkConditionsLink(
683
818
  for (const sortField of linkStepObject.sortFields) {
684
819
  console.log('sortField: ', sortField);
685
820
  console.log('requiredDataLinkSteps: ', requiredDataLinkSteps);
821
+ console.log('requiredDataLinkStepObjects: ', requiredDataLinkStepObjects);
686
822
  let requiredDataLinkStepSortField = requiredDataLinkStepObjects[sortField.requiredDataLinkStepObjectId];
687
823
  console.log('requiredDataLinkStepSortField: ', requiredDataLinkStepSortField);
688
-
689
- console.log(' requiredDataLinkStepSortField.linkSteps: ', requiredDataLinkStepSortField.linkSteps);
824
+ console.log(' requiredDataLinkStepSortField.linkSteps: ', {
825
+ linkSteps: requiredDataLinkStepSortField.linkSteps,
826
+ requiredDataLinkStepSortField: requiredDataLinkStepSortField
827
+ });
690
828
 
691
829
  //* make all linkPath in here and send out to combine allLinkPath
692
- let [fieldName, childLinkStep, linkErrorsObject, linkErrorsFound] = await createLinkPath(
830
+ let [fieldName, childLinkStep, linkErrorsObject, linkErrorsFound, sortObj] = await createLinkPath(
831
+ linkStepObject.pathLinkType.objType,
693
832
  requiredDataLinkStepSortField.linkSteps,
694
833
  requiredDataLinkStepObjects,
695
834
  requiredDataLinkSteps,
696
835
  perParentCombinations,
697
836
  complexFilterCombinations,
698
837
  values,
838
+ filtersStructure,
839
+ [],
699
840
  errorsObject,
700
841
  errorsFound
701
842
  );
@@ -703,7 +844,8 @@ async function checkConditionsLink(
703
844
  fieldName,
704
845
  childLinkStep,
705
846
  linkErrorsObject,
706
- linkErrorsFound
847
+ linkErrorsFound,
848
+ sortObj
707
849
  });
708
850
 
709
851
  if (linkErrorsFound > 0) {
@@ -766,10 +908,19 @@ async function checkConditionsLink(
766
908
  });
767
909
  };
768
910
 
769
- sortFieldObjects.push({
911
+ let sortObject = {
770
912
  fieldName: fieldName,
771
- dataType: sortField.dataType
772
- });
913
+ // dataType: sortField.dataType
914
+ }
915
+
916
+ if (sortObj !== null) {
917
+ if (sortObj.dataType === "array") {
918
+ sortObject.dataType = sortObj.dataType
919
+ sortObject.values = sortObj.value;
920
+ }
921
+ }
922
+
923
+ sortFieldObjects.push(sortObject);
773
924
  console.log('sortFieldObjects: ', sortFieldObjects);
774
925
 
775
926
  };
@@ -17,10 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  "use strict";
19
19
 
20
- import { objectHash as hash } from '@izara_project/izara-shared-core'; //const hash = require('@izara_project/izara-shared-core').objectHash;
20
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
21
21
  import lodash from 'lodash';
22
+ import objectHash from 'object-hash';
22
23
  const { isEmpty } = lodash;
23
- import complexFilterShared from '@izara_project/izara-core-library-complex-filter';
24
24
 
25
25
  function validateFilterElement(
26
26
  filterElements,
@@ -76,58 +76,65 @@ function createFiltersRequest(
76
76
  let filterMainId = null;
77
77
  let filterMainObject = {};
78
78
  let operation = null;
79
+ let nextFilterElementId = null;
79
80
 
80
81
  let errorsObject = {};
81
82
  let errorsFound = [];
82
83
  let status = 'valid';
83
84
 
84
- //* validate combine logicalStructure
85
- let [validateObject, validateFilterMainId, validateFilterObject, validateErrorsObject, validateErrors] = validateCombinationStructure(
86
- objType,
87
- initialLogicalElementId,
88
- logicalElements,
89
- values
90
- );
91
- console.log('return validateCombinationStructure: ', {
92
- validateObject,
93
- validateFilterMainId,
94
- validateFilterObject,
95
- validateErrorsObject,
96
- validateErrors
97
- });
98
-
99
- if (!validateObject || validateErrors.length > 0) {
100
- Object.assign(errorsObject, validateErrorsObject);
101
- errorsFound = errorsFound.concat(validateErrors);
102
- return [
103
- null,
104
- 'invalid',
105
- errorsObject,
106
- errorsFound
107
- ];
108
- };
85
+ // //* validate combine logicalStructure
86
+ // let [validateObject, validateFilterMainId, validateFilterObject, validateErrorsObject, validateErrors] = validateCombinationStructure(
87
+ // objType,
88
+ // initialLogicalElementId,
89
+ // logicalElements,
90
+ // values
91
+ // );
92
+ // console.log('return validateCombinationStructure: ', {
93
+ // validateObject,
94
+ // validateFilterMainId,
95
+ // validateFilterObject,
96
+ // validateErrorsObject,
97
+ // validateErrors
98
+ // });
99
+
100
+ // if (!validateObject || validateErrors.length > 0) {
101
+ // Object.assign(errorsObject, validateErrorsObject);
102
+ // errorsFound = errorsFound.concat(validateErrors);
103
+ // return [
104
+ // null,
105
+ // 'invalid',
106
+ // errorsObject,
107
+ // errorsFound
108
+ // ];
109
+ // };
109
110
 
110
111
  let operationErrorsObject = {};
111
112
  let operationErrors = [];
113
+ let returnFilterElements = {};
112
114
 
113
115
  [
114
116
  filterMainId,
115
117
  filterMainObject,
116
118
  operation,
117
119
  operationErrorsObject,
118
- operationErrors
120
+ operationErrors,
121
+ nextFilterElementId,
122
+ returnFilterElements
119
123
  ] = filterLogicalElements(
120
124
  objType,
121
125
  initialLogicalElementId,
122
126
  logicalElements,
123
127
  values,
124
128
  );
129
+
125
130
  console.log('final return filterLogicalElements: ', {
126
131
  filterMainId,
127
132
  filterMainObject,
128
133
  operation,
129
134
  operationErrorsObject,
130
- operationErrors
135
+ operationErrors,
136
+ nextFilterElementId,
137
+ returnFilterElements
131
138
  });
132
139
 
133
140
  if (errorsFound.length > 0 || filterMainId === null) {
@@ -142,10 +149,9 @@ function createFiltersRequest(
142
149
  };
143
150
 
144
151
  let filterElements = {};
145
- if (filterMainObject.filterElement.hasOwnProperty('filterElements')) {
146
- filterElements = filterMainObject.filterElement.filterElements;
147
-
148
- delete filterMainObject.filterElement.filterElements;
152
+ // if (filterMainObject.filterElement.hasOwnProperty('filterElements') || isEmpty(returnFilterElements)) {
153
+ if (!isEmpty(returnFilterElements)) {
154
+ filterElements = returnFilterElements;
149
155
  Object.assign(filterElements, { [filterMainId]: filterMainObject });
150
156
  };
151
157
 
@@ -162,18 +168,6 @@ function createFiltersRequest(
162
168
  };
163
169
  console.log('complexFilterRequest: ', complexFilterRequest);
164
170
 
165
- // let validate = validateFilterElement(
166
- // complexFilterRequest.filterElements,
167
- // logicalElements
168
- // );
169
- // _izContext.logger.debug('validate: ', validate);
170
-
171
- // if (validate === false) {
172
- // errorsObject[initialLogicalElementId] = 'filterElements has create fail';
173
- // errorsFound.push("filterElements has create fail");
174
- // return [null, "error", errorsObject, errorsFound]
175
- // }
176
-
177
171
  return [
178
172
  complexFilterRequest,
179
173
  status,
@@ -273,7 +267,9 @@ function validateCombinationStructure(
273
267
  initialLogicalElementId = nextElementId;
274
268
  };
275
269
 
276
- } else if (logicalElementType === 'closeBracket') {
270
+ }
271
+
272
+ if (logicalElementType === 'closeBracket') {
277
273
  console.log('----------------- closeBracket --------------');
278
274
 
279
275
  return [
@@ -640,7 +636,9 @@ function validateOperation(
640
636
  // check if is an operation, if not simply return currentFilterMainId
641
637
  if (!runningFilterObject || !lastLogicalOperator) {
642
638
  console.log("+++ validate no operation, R E T U R N currentFilterMainId ++");
643
- return [currentFilterMainId, currentFilterObject, null, errorsFound];
639
+ let filterElements = currentFilterObject.filterElement.filterElements;
640
+ delete currentFilterObject.filterElement.filterElements;
641
+ return [currentFilterMainId, currentFilterObject, null, errorsFound, filterElements];
644
642
  }
645
643
 
646
644
  let filterElements = splitFilterElements(
@@ -650,6 +648,8 @@ function validateOperation(
650
648
  currentFilterObject
651
649
  );
652
650
 
651
+ console.log("----------------------------------------------------- filterElements", filterElements);
652
+
653
653
  // create new operation FilterObject
654
654
  let operationFilterObject = {
655
655
  objType: objType,
@@ -667,6 +667,7 @@ function validateOperation(
667
667
  console.log("==== validate operationFilterMainId After Hash =====", operationFilterMainId);
668
668
 
669
669
  console.log("RETURN validate operationFilterMainId ==>", operationFilterMainId);
670
+ delete operationFilterObject.filterElement.filterElements;
670
671
  console.log("RETURN validate operationFilterObject ==>", operationFilterObject);
671
672
  console.log("========= [validateOperation ::: End] =======");
672
673
 
@@ -676,7 +677,7 @@ function validateOperation(
676
677
  filterMainIdB: currentFilterMainId,
677
678
  };
678
679
 
679
- return [operationFilterMainId, operationFilterObject, operation, errorsFound];
680
+ return [operationFilterMainId, operationFilterObject, operation, errorsFound, filterElements];
680
681
 
681
682
  } catch (err) {
682
683
  throw (err)
@@ -688,6 +689,7 @@ function filterLogicalElements(
688
689
  initialLogicalElementId,
689
690
  logicalElements,
690
691
  values,
692
+ // filterElements = {},
691
693
  nextLogicalElementId = null,
692
694
  runningFilterMainId = null,
693
695
  runningFilterObject = null,
@@ -716,6 +718,8 @@ function filterLogicalElements(
716
718
  let lastNextLogicalElementId = null;
717
719
  let currentLogicalElementId = initialLogicalElementId;
718
720
 
721
+ let filterElements = {};
722
+
719
723
  if (nextLogicalElementId !== null) {
720
724
  currentLogicalElementId = nextLogicalElementId;
721
725
  }
@@ -735,9 +739,24 @@ function filterLogicalElements(
735
739
  let logicalElementType = logicalElement.logicalElementType;
736
740
  console.log('logicalElementType: ', logicalElementType);
737
741
 
742
+ if (logicalElementType === "operation") {
743
+
744
+ lastLogicalOperator = logicalElement.operation;
745
+
746
+ if (logicalElement.nextLogicalElementId === null) {
747
+ errorsObject[initialLogicalElementId] = `this operation structure must set nextLogicalElementId`;
748
+ errorsFound.push(`this logical structure logicalElementId: ${currentLogicalElementId} must set nextLogicalElementId`);
749
+ }
750
+
751
+ logicalElement = logicalElements[logicalElement.nextLogicalElementId];
752
+ logicalElementType = logicalElement.logicalElementType;
753
+
754
+ }
755
+
738
756
  if (logicalElementType === "openBracket") {
739
757
 
740
758
  let nextElementId = null;
759
+ let returnFilterElements = {};
741
760
 
742
761
  [
743
762
  currentFilterMainId,
@@ -745,12 +764,14 @@ function filterLogicalElements(
745
764
  operation,
746
765
  errorsObject,
747
766
  errorsFound,
748
- nextElementId
767
+ nextElementId,
768
+ returnFilterElements
749
769
  ] = filterLogicalElements(
750
770
  objType,
751
771
  initialLogicalElementId,
752
772
  logicalElements,
753
773
  values,
774
+ // filterElements,
754
775
  logicalElement.nextLogicalElementId
755
776
  );
756
777
  console.log('return filterLogicalElement for openBracket: ', {
@@ -758,9 +779,12 @@ function filterLogicalElements(
758
779
  currentFilterObject,
759
780
  operation,
760
781
  errorsObject, errorsFound,
761
- lastNextLogicalElementId
782
+ lastNextLogicalElementId,
783
+ returnFilterElements
762
784
  });
763
785
 
786
+ console.log("bb", bb)
787
+
764
788
  if (nextElementId !== null) {
765
789
  lastNextLogicalElementId = nextElementId;
766
790
  }
@@ -776,18 +800,6 @@ function filterLogicalElements(
776
800
  logicalElement.nextLogicalElementId
777
801
  ]
778
802
 
779
- } else if (logicalElementType === "operation") {
780
-
781
- lastLogicalOperator = logicalElement.operation;
782
-
783
- if (logicalElement.nextLogicalElementId === null) {
784
- errorsObject[initialLogicalElementId] = `this operation structure must set nextLogicalElementId`;
785
- errorsFound.push(`this logical structure logicalElementId: ${currentLogicalElementId} must set nextLogicalElementId`);
786
- }
787
-
788
- logicalElement = logicalElements[logicalElement.nextLogicalElementId];
789
- logicalElementType = logicalElement.logicalElementType;
790
-
791
803
  }
792
804
 
793
805
  console.log("check logicalElement: ", logicalElement);
@@ -922,12 +934,14 @@ function filterLogicalElements(
922
934
  operation,
923
935
  childErrorsObject,
924
936
  childErrorsFound,
925
- childNextLogicalElementId
937
+ childNextLogicalElementId,
938
+ returnFilterElements
926
939
  ] = filterLogicalElements(
927
940
  logicalElement.pathLinkType.objType,
928
941
  initialLogicalElementId,
929
942
  logicalElements,
930
943
  values,
944
+ // filterElements,
931
945
  logicalElement.childLogicalElementId
932
946
  );
933
947
  console.log('return child filterLogicalElement for child complexFilter: ', {
@@ -936,23 +950,35 @@ function filterLogicalElements(
936
950
  operation,
937
951
  childErrorsObject,
938
952
  childErrorsFound,
939
- childNextLogicalElementId
953
+ childNextLogicalElementId,
954
+ returnFilterElements
940
955
  });
941
956
  if (childErrorsFound.length > 0) {
942
957
  Object.assign(errorsObject, childErrorsObject);
943
958
  errorsFound = errorsFound.concat(childErrorsFound)
944
959
  }
945
960
 
946
- let filterElements = splitFilterElements(
947
- childFilterMainId,
948
- childFilterObject
949
- );
950
- console.log('filterElements: ', filterElements);
961
+ delete childFilterObject.filterElement.filterElements;
962
+
963
+ if (isEmpty(returnFilterElements)) {
964
+ returnFilterElements = { [childFilterMainId]: childFilterObject };
965
+ } else {
966
+ returnFilterElements[childFilterMainId] = childFilterObject;
967
+ }
968
+
969
+
970
+ // let childFilterElements = splitFilterElements(
971
+ // childFilterMainId,
972
+ // childFilterObject
973
+ // );
974
+ // console.log('childFilterElements: ', childFilterElements);
975
+
976
+ Object.assign(filterElements, returnFilterElements);
951
977
  let setRequestProperties = {};
952
978
 
953
979
  if (!isEmpty(logicalElement.requestProperties)) {
954
980
  console.log('logicalElement: ', logicalElement);
955
-
981
+ console.log("ll", ll)
956
982
  for (const [tag, requestPropertyId] of Object.entries(logicalElement.requestProperties)) {
957
983
  console.log('set requestProperties: ', { tag, requestPropertyId });
958
984
 
@@ -973,13 +999,13 @@ function filterLogicalElements(
973
999
  objType: logicalElement.objType,
974
1000
  filterElement: {
975
1001
  filterType: logicalElementType,
976
- filterElements: filterElements,
1002
+ filterElements: returnFilterElements,
977
1003
  childFilterElementId: childFilterMainId,
978
1004
  pathLinkType: logicalElement.pathLinkType,
979
1005
  requestProperties: setRequestProperties ?? {}
980
1006
  }
981
1007
  };
982
- console.log('currentFilterObject: ', currentFilterObject);
1008
+ console.log('currentFilterObject: ', currentFilterObject)
983
1009
 
984
1010
  currentFilterMainId = hash(currentFilterObject);
985
1011
  console.log('currentFilterMainId: ', currentFilterMainId);
@@ -1005,8 +1031,9 @@ function filterLogicalElements(
1005
1031
 
1006
1032
  if (lastNextLogicalElementId !== null) {
1007
1033
 
1008
- // [runningFilterMainId, runningFilterObject, operation, operationErrorsFound] = complexFilterShared.validateOperation(
1009
- [runningFilterMainId, runningFilterObject, operation, operationErrorsFound] = validateOperation(
1034
+ let validateFilterElements = {};
1035
+
1036
+ [runningFilterMainId, runningFilterObject, operation, operationErrorsFound, validateFilterElements] = validateOperation(
1010
1037
  objType,
1011
1038
  runningFilterMainId,
1012
1039
  runningFilterObject,
@@ -1014,13 +1041,19 @@ function filterLogicalElements(
1014
1041
  currentFilterMainId,
1015
1042
  currentFilterObject
1016
1043
  );
1017
- console.log('return validateOperation for lastNextLogicalElementId == null: ', {
1044
+ console.log('return validateOperation for lastNextLogicalElementId !== null: ', {
1018
1045
  runningFilterMainId,
1019
1046
  runningFilterObject,
1020
1047
  operation,
1021
- operationErrorsFound
1048
+ operationErrorsFound,
1049
+ validateFilterElements
1022
1050
  });
1023
1051
 
1052
+ if (currentFilterObject.objType.objectType === "productStandard") {
1053
+ console.log("ff", currentFilterObject.filterElement.filterElements)
1054
+ console.log("ff", ff)
1055
+ }
1056
+
1024
1057
  if (!isEmpty(operation)) {
1025
1058
  lastLogicalOperator = null;
1026
1059
  }
@@ -1031,24 +1064,27 @@ function filterLogicalElements(
1031
1064
  operations,
1032
1065
  nextErrorObject,
1033
1066
  nextErrorFound,
1034
- nextElementId
1067
+ nextElementId,
1068
+ returnFilterElements
1035
1069
  ] = filterLogicalElements(
1036
1070
  objType,
1037
1071
  initialLogicalElementId,
1038
1072
  logicalElements,
1039
1073
  values,
1074
+ // filterElements,
1040
1075
  lastNextLogicalElementId,
1041
1076
  runningFilterMainId,
1042
1077
  runningFilterObject,
1043
1078
  lastLogicalOperator,
1044
1079
  );
1045
- console.log('return validateOperation for lastNextLogicalElementId !== null: ', {
1080
+ console.log('return validateOperation for lastNextLogicalElementId !== null ___1: ', {
1046
1081
  nextFilterMainId,
1047
1082
  nextFilterObject,
1048
1083
  operations,
1049
1084
  nextErrorObject,
1050
1085
  nextErrorFound,
1051
- nextElementId
1086
+ nextElementId,
1087
+ returnFilterElements
1052
1088
  });
1053
1089
 
1054
1090
  if (nextErrorFound.length > 0) {
@@ -1056,7 +1092,10 @@ function filterLogicalElements(
1056
1092
  errorsFound = errorsFound.concat(nextErrorFound);
1057
1093
  }
1058
1094
 
1095
+ Object.assign(filterElements, validateFilterElements, returnFilterElements);
1096
+
1059
1097
  if (nextElementId !== null) {
1098
+
1060
1099
  let filterErrorObject = {};
1061
1100
  let filterErrorFound = [];
1062
1101
 
@@ -1066,18 +1105,19 @@ function filterLogicalElements(
1066
1105
  operation,
1067
1106
  filterErrorObject,
1068
1107
  filterErrorFound,
1069
- nextElementId
1108
+ nextElementId,
1070
1109
  ] = filterLogicalElements(
1071
1110
  objType,
1072
1111
  initialLogicalElementId,
1073
1112
  logicalElements,
1074
1113
  values,
1114
+ // filterElements,
1075
1115
  nextElementId,
1076
1116
  nextFilterMainId,
1077
1117
  nextFilterObject,
1078
1118
  lastLogicalOperator
1079
1119
  );
1080
- console.log('return validateOperation for lastNextLogicalElementId !== null: ', {
1120
+ console.log('return validateOperation for lastNextLogicalElementId !== null ___2: ', {
1081
1121
  runningFilterMainId,
1082
1122
  runningFilterObject,
1083
1123
  operation,
@@ -1094,19 +1134,22 @@ function filterLogicalElements(
1094
1134
  nextElementId
1095
1135
  ];
1096
1136
  } else {
1137
+
1097
1138
  return [
1098
1139
  nextFilterMainId,
1099
1140
  nextFilterObject,
1100
1141
  operation,
1101
1142
  errorsObject,
1102
1143
  errorsFound,
1103
- nextElementId
1144
+ nextElementId,
1145
+ filterElements
1104
1146
  ];
1105
1147
  }
1106
1148
 
1107
1149
  } else {
1150
+ let returnFilterElements = {};
1108
1151
 
1109
- [runningFilterMainId, runningFilterObject, operation, operationErrorsFound] = validateOperation(
1152
+ [runningFilterMainId, runningFilterObject, operation, operationErrorsFound, returnFilterElements] = validateOperation(
1110
1153
  objType,
1111
1154
  runningFilterMainId,
1112
1155
  runningFilterObject,
@@ -1118,14 +1161,15 @@ function filterLogicalElements(
1118
1161
  runningFilterMainId,
1119
1162
  runningFilterObject,
1120
1163
  operation,
1121
- operationErrorsFound
1164
+ operationErrorsFound,
1165
+ returnFilterElements
1122
1166
  });
1123
1167
 
1124
1168
  if (operationErrorsFound.length > 0) {
1125
1169
  errorsFound = errorsFound.concat(operationErrorsFound)
1126
1170
  }
1127
1171
 
1128
- return [runningFilterMainId, runningFilterObject, operation, errorsObject, errorsFound, null];
1172
+ return [runningFilterMainId, runningFilterObject, operation, errorsObject, errorsFound, null, returnFilterElements];
1129
1173
 
1130
1174
  }
1131
1175
 
@@ -1152,14 +1196,14 @@ function splitFilterElements(
1152
1196
  // || runningFilterObject.filterElement.filterType === 'traversal'
1153
1197
  // ) {}
1154
1198
 
1155
- if (runningFilterObject.logicalElementType === 'operation') {
1199
+ if (runningFilterObject.filterElement.filterType === 'operation') {
1156
1200
  console.log('-------- operation ----------');
1157
1201
 
1158
1202
  Object.assign(filterElements, runningFilterObject.filterElement.filterElements);
1159
1203
  // delete runningFilterObject.filterElement.filterElements;
1160
1204
  filterElements[runningFilterMainId] = runningFilterObject;
1161
1205
 
1162
- } else if (runningFilterObject.logicalElementType === 'childComplexFilter') {
1206
+ } else if (runningFilterObject.filterElement.filterType === 'childComplexFilter') {
1163
1207
  console.log('-------- childComplexFilter ----------');
1164
1208
 
1165
1209
  Object.assign(filterElements, runningFilterObject.filterElement.filterElements);
@@ -1167,28 +1211,28 @@ function splitFilterElements(
1167
1211
  filterElements[runningFilterMainId] = runningFilterObject;
1168
1212
 
1169
1213
  } else {
1170
- console.log(` -------- ${runningFilterObject.logicalElementType} ----------`);
1214
+ console.log(` -------- ${runningFilterObject.filterElement.filterType} ----------`);
1171
1215
  //'logical'| 'identifiers'|'translateIds'|'traversal'
1172
1216
  filterElements[runningFilterMainId] = runningFilterObject;
1173
1217
  };
1174
1218
 
1175
1219
  if (currentFilterObject !== null) {
1176
- if (currentFilterObject.logicalElementType === 'operation') {
1220
+ if (currentFilterObject.filterType === 'operation') {
1177
1221
  console.log('-------- operation ----------');
1178
1222
 
1179
1223
  Object.assign(filterElements, currentFilterObject.filterElement.filterElements);
1180
1224
  // delete currentFilterObject.filterElement.filterElements;
1181
1225
  filterElements[currentFilterMainId] = currentFilterObject;
1182
1226
 
1183
- } else if (currentFilterObject.logicalElementType === 'childComplexFilter') {
1227
+ } else if (currentFilterObject.filterElement.filterType === 'childComplexFilter') {
1184
1228
  console.log('-------- childComplexFilter ----------');
1185
1229
 
1186
1230
  Object.assign(filterElements, currentFilterObject.filterElement.filterElements);
1187
- // delete currentFilterObject.filterElement.filterElements;
1231
+ delete currentFilterObject.filterElement.filterElements;
1188
1232
  filterElements[currentFilterMainId] = currentFilterObject;
1189
1233
 
1190
1234
  } else {
1191
- console.log(` -------- ${currentFilterObject.logicalElementType} ----------`);
1235
+ console.log(` -------- ${currentFilterObject.filterElement.filterType} ----------`);
1192
1236
  //'logical'| 'identifiers'|'translateIds'|'traversal'
1193
1237
  filterElements[currentFilterMainId] = currentFilterObject;
1194
1238
  };
@@ -1203,7 +1247,7 @@ export default {
1203
1247
  //* create filter
1204
1248
  createFiltersRequest,
1205
1249
  validateCombinationStructure,
1206
- // validateOperation,
1207
1250
  filterLogicalElements,
1251
+ // validateOperation,
1208
1252
  // splitFilterElements,
1209
1253
  }
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
  import LogicalStructureSharedLib from './LogicalStructureSharedLib.js';
20
20
 
21
- function initSchemaFn(getObjSchemaS3WithoutHierarchy, getObjectRelationship) { //getObjectLinks
22
- return LogicalStructureSharedLib.initSchemaFn(getObjSchemaS3WithoutHierarchy, getObjectRelationship);
21
+ function initSchemaFn(getObjSchemaS3WithHierarchyShared, getObjectLinksShared) {
22
+ return LogicalStructureSharedLib.initSchemaFn(getObjSchemaS3WithHierarchyShared, getObjectLinksShared);
23
23
  }
24
24
 
25
25
  export default {
@@ -18,24 +18,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
 
21
- import { objectHash as hash } from '@izara_project/izara-shared-core'; //const hash = require('@izara_project/izara-shared-core').objectHash;
21
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
22
22
  import lodash from 'lodash';
23
23
  const { isEmpty } = lodash;
24
- import { v4 as uuidV4 } from 'uuid'; //const { v4: uuidv4 } = require('uuid');
25
- // import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
24
+ import { v4 as uuidV4 } from 'uuid';
26
25
  const MAX_ITER = 4;
27
26
 
28
27
  let getObjectSchema = {};
29
28
 
30
- function initSchemaFn(getObjSchemaS3WithoutHierarchy, getObjectRelationship) { //getObjectLinks
29
+ function initSchemaFn(getObjSchemaS3WithHierarchyShared, getObjectLinksShared) {
31
30
  getObjectSchema = {
32
- getObjSchemaS3WithoutHierarchy,
33
- getObjectRelationship: getObjectRelationship // getObjectRelationship: getObjectLinks
31
+ getObjSchemaS3WithHierarchyShared,
32
+ getObjectLinksShared
34
33
  }
35
-
36
34
  return getObjectSchema;
37
35
  }
38
36
 
37
+
39
38
  function combineLogicalStructure(
40
39
  objType,
41
40
  initialLogicalElementId,
@@ -752,7 +751,7 @@ async function changeObjTypePath(
752
751
  if (!childLogicalElement.hasOwnProperty('childLogicalElementId')) {
753
752
 
754
753
  // let childSchema = await getObjectSchema.getObjSchemaS3WithCache(
755
- let childSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchyV2(
754
+ let childSchema = await getObjectSchema.getObjSchemaS3WithHierarchyShared(
756
755
  childLogicalElement.objType
757
756
  );
758
757
  console.log('childSchema: ', childSchema);
@@ -810,7 +809,6 @@ async function changeObjTypePath(
810
809
 
811
810
  let logicalStructure = {};
812
811
  [previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
813
- _izContext,
814
812
  logicalElements,
815
813
  previousLogicalElementId,
816
814
  previousLogicalElement,
@@ -860,7 +858,6 @@ async function changeObjTypePath(
860
858
  let logicalStructure = {};
861
859
  // change function name ==> set logicalElementId
862
860
  [previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
863
- _izContext,
864
861
  logicalElements,
865
862
  previousLogicalElementId,
866
863
  previousLogicalElement,
@@ -909,9 +906,7 @@ async function changeObjTypePath(
909
906
  };
910
907
 
911
908
  };
912
- //###################################################################################################################################################################################
913
-
914
-
909
+ // ###################################################################################################################################################################################
915
910
 
916
911
 
917
912
  function createChildComplexFilterStructure(
@@ -1028,9 +1023,7 @@ async function recursiveFindObjTypeTypePathToAnotherObjType(
1028
1023
  return [null, errorsObject, errorsFound];
1029
1024
  };
1030
1025
 
1031
- // let objectRelationship = await getObjectSchema.getObjectRelationshipWithCache(
1032
- const objectRelationship = await getObjectSchema.getObjectRelationship(
1033
- {}, //_izContext maybe delete
1026
+ const objectRelationship = await getObjectSchema.getObjectLinksShared(
1034
1027
  fromObjType
1035
1028
  );
1036
1029
  console.log("objectRelationship: ", { fromObjType, objectRelationship });
@@ -1063,8 +1056,7 @@ async function recursiveFindObjTypeTypePathToAnotherObjType(
1063
1056
  };
1064
1057
 
1065
1058
  // const objectSchema = await getObjectSchema.getObjSchemaS3WithCache(
1066
- const objectSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchy(
1067
- {}, //_izContext maybe delete
1059
+ const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchyShared(
1068
1060
  toObjType,
1069
1061
  );
1070
1062
  console.log('objectSchema: ', objectSchema);
@@ -18,12 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  "use strict";
19
19
 
20
20
  //* searchResultMain record
21
- import { objectHash as hash } from '@izara_project/izara-shared-core'; //const hash = require('@izara_project/izara-shared-core').objectHash;
21
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
22
22
  import lodash from 'lodash';
23
23
  const { isEmpty } = lodash;
24
- import filtersSharedLib from './FiltersSharedLib.js'; //const filtersSharedLib = require('./FiltersSharedLib');
24
+ import filtersSharedLib from './FiltersSharedLib.js';
25
25
  import dataFieldsSharedLib from './DataFieldsSharedLib.js';
26
- import LogicalStructureSharedLib from './LogicalStructureSharedLib.js';
26
+
27
27
 
28
28
  async function createSearchRequest(
29
29
  objType,
@@ -35,7 +35,6 @@ async function createSearchRequest(
35
35
  requiredDataLinkStepObjects,
36
36
  requiredDataLinkSteps,
37
37
  values,
38
- getSchemaFn
39
38
  ) {
40
39
  console.log('createSearchResult: ', {
41
40
  objType,
@@ -57,13 +56,14 @@ async function createSearchRequest(
57
56
 
58
57
  let requiredDataPromise = dataFieldsSharedLib.createRequiredData(
59
58
  objType,
59
+ initialLogicalElementId,
60
+ logicalElements,
60
61
  requiredDataFields,
61
62
  complexFilterCombinations,
62
63
  perParentCombinations,
63
64
  requiredDataLinkStepObjects,
64
65
  requiredDataLinkSteps,
65
66
  values,
66
- getSchemaFn
67
67
  );
68
68
 
69
69
  //* create complexFilter normalize to send backend
@@ -105,11 +105,11 @@ async function createSearchRequest(
105
105
  let requiredData = await requiredDataPromise;
106
106
  console.log('return create requiredData: ', requiredData);
107
107
 
108
- // if (requiredData.status === 'invalid' || requiredData.errorsFound.length > 0) {
109
- // Object.assign(errorsObject, requiredData.errorsObject)
110
- // errorsFound.push('requiredData cannot create');
111
- // errorsFound = errorsFound.concat(requiredData.errorsFound);
112
- // }
108
+ if (requiredData.status === 'invalid' || requiredData.errorsFound.length > 0) {
109
+ Object.assign(errorsObject, requiredData.errorsObject)
110
+ errorsFound.push('requiredData cannot create');
111
+ errorsFound = errorsFound.concat(requiredData.errorsFound);
112
+ }
113
113
 
114
114
  if (errorsFound.length > 0) {
115
115
  return [null, 'invalid', errorsObject, errorsFound]