@gudhub/core 1.1.71 → 1.1.73

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.
@@ -29,12 +29,12 @@ describe("FIELD PROCESSOR", async function() {
29
29
  })
30
30
 
31
31
  it('CREATE ITEM AND SET IT VALUE / should return new value of new item', async () => {
32
- let items = await gudhub.addNewItems(16259, newItems);
32
+ let items = await gudhub.addNewItems(214, newItems);
33
33
  let item_id = items[0].item_id;
34
34
 
35
- await gudhub.setFieldValue(16259, item_id, 254056, 'Big Fish Tank');
35
+ await gudhub.setFieldValue(214, item_id, 254056, 'Big Fish Tank');
36
36
 
37
- let value = await gudhub.getFieldValue(16259, item_id, 254056);
37
+ let value = await gudhub.getFieldValue(214, item_id, 254056);
38
38
 
39
39
  value.should.equal('Big Fish Tank');
40
40
  });
@@ -7,52 +7,52 @@ describe("ITEM PROCESSOR", async function () {
7
7
 
8
8
 
9
9
  it("GET ITEM / should return an item", async () => {
10
- let item = await gudhub.getItem(16259, 1064673);
11
- item.item_id.should.equal(1064673)
10
+ let item = await gudhub.getItem(214, 1175);
11
+ item.item_id.should.equal(1175)
12
12
  let itemType = typeof item;
13
13
  itemType.should.equal('object');
14
14
  });
15
15
 
16
16
  it("ADD ITEM AND GET IT / should return new item twice", async () => {
17
- let items = await gudhub.addNewItems(16259, newItems);
17
+ let items = await gudhub.addNewItems(214, newItems);
18
18
 
19
19
  let isItemsArray = Array.isArray(items);
20
20
 
21
21
  isItemsArray.should.equal(true);
22
22
  items[0].fields[0].field_value.should.equal('Big Fish Tank');
23
23
 
24
- let item = await gudhub.getItem(16259, items[0].item_id);
24
+ let item = await gudhub.getItem(214, items[0].item_id);
25
25
 
26
26
  item.fields[0].field_value.should.equal('Big Fish Tank');
27
27
  });
28
28
 
29
29
  it("ADD NEW ITEM AND GET ITS VALUE / should return new item's value", async () => {
30
- let items = await gudhub.addNewItems(16259, newItems);
30
+ let items = await gudhub.addNewItems(214, newItems);
31
31
  let item_id = items[0].item_id;
32
32
 
33
- let value = await gudhub.getFieldValue(16259, item_id, 254056);
33
+ let value = await gudhub.getFieldValue(214, item_id, 254056);
34
34
 
35
35
  value.should.equal('Big Fish Tank');
36
36
  });
37
37
 
38
38
  it("ADD NEW ITEM, UPDATE ITS VALUE AND GET IT / should return updated value of new item", async () => {
39
- let items = await gudhub.addNewItems(16259, newItems);
39
+ let items = await gudhub.addNewItems(214, newItems);
40
40
  let item_id = items[0].item_id;
41
41
 
42
- await gudhub.setFieldValue(16259, item_id, 254056, 'Updated value');
42
+ await gudhub.setFieldValue(214, item_id, 254056, 'Updated value');
43
43
 
44
- let value = await gudhub.getFieldValue(16259, item_id, 254056);
44
+ let value = await gudhub.getFieldValue(214, item_id, 254056);
45
45
 
46
46
  value.should.equal('Updated value');
47
47
  });
48
48
 
49
49
  it("ADD NEW ITEM, THEN DELETE IT / should return null", async () => {
50
- let items = await gudhub.addNewItems(16259, newItems);
50
+ let items = await gudhub.addNewItems(214, newItems);
51
51
  let item_id = items[0].item_id;
52
52
 
53
- await gudhub.deleteItems(16259, [item_id]);
53
+ await gudhub.deleteItems(214, [item_id]);
54
54
 
55
- let value = await gudhub.getFieldValue(16259, item_id, 254056);
55
+ let value = await gudhub.getFieldValue(214, item_id, 254056);
56
56
 
57
57
  let isValueNull = value === null ? true : false;
58
58
 
@@ -33,12 +33,9 @@ export class Utils {
33
33
  this.FileHelper = new FileHelper(gudhub);
34
34
  }
35
35
 
36
- prefilter(filters_list, element_app_id, app_id, item_id, variables = []) {
36
+ prefilter(filters_list, variables = {}) {
37
37
  return filterPreparation(
38
38
  filters_list,
39
- element_app_id,
40
- app_id,
41
- item_id,
42
39
  this.gudhub.storage,
43
40
  this.gudhub.pipeService,
44
41
  variables
@@ -69,9 +66,11 @@ export class Utils {
69
66
  ) {
70
67
  const modified_filters_list = await this.prefilter(
71
68
  filters_list,
72
- element_app_id,
73
- app_id,
74
- item_id
69
+ {
70
+ element_app_id,
71
+ app_id,
72
+ item_id
73
+ }
75
74
  );
76
75
  const itemsList = this.filter(items, modified_filters_list);
77
76
  const newItems = this.group(field_group, itemsList);
@@ -69,6 +69,29 @@ import { app_8263 } from '../../../fake_server/fake_server_data/app_8263.js';
69
69
  const filteredItems = gudhub.filter(app_8263.items_list, filters);
70
70
  filteredItems.length.should.equal(8);
71
71
  });
72
+
73
+ it('PREFILTER WITH VARIABLES / should return variables values instead of names', async () => {
74
+ const filters = [
75
+ {
76
+ "field_id": 96606,
77
+ "data_type": "text",
78
+ "input_type": "variable",
79
+ "input_value": "current_app,boolean",
80
+ "search_type": "contain_or"
81
+ }
82
+ ]
83
+
84
+ const variables = {
85
+ current_app_id: 1,
86
+ boolean: true
87
+ }
88
+
89
+ const filter = await gudhub.prefilter(filters, variables);
90
+
91
+ filter[0].valuesArray[0].should.equal(1);
92
+ filter[0].valuesArray[1].should.equal(true);
93
+
94
+ });
72
95
 
73
96
  });
74
97
 
@@ -1,24 +1,21 @@
1
1
  export async function filterPreparation(
2
2
  filters_list,
3
- element_app_id,
4
- current_app_id,
5
- item_id,
6
3
  storage,
7
4
  pipeService,
8
- variables = []
5
+ variables = {}
9
6
  ) {
10
7
  const filterArray = [];
11
8
 
12
9
  const objectMethod = {
13
10
  variableMethodcurrent_app() {
14
- return [current_app_id];
11
+ return [variables.current_app_id || variables.app_id];
15
12
  },
16
13
  variableMethodelement_app() {
17
- return [element_app_id];
14
+ return [variables.element_app_id];
18
15
  },
19
16
 
20
17
  variableMethodcurrent_item() {
21
- const currentValue = `${current_app_id}.${item_id}`;
18
+ const currentValue = `${variables.current_app_id || variables.app_id}.${variables.item_id}`;
22
19
  return [currentValue];
23
20
  },
24
21
 
@@ -48,8 +45,8 @@ export async function filterPreparation(
48
45
  start_date.valueOf().toString() + ":" + end_date.valueOf().toString();
49
46
  return [result];
50
47
  },
51
- variableMethodvariable() {
52
- return variables;
48
+ variableMethodvariable(property) {
49
+ return [variables[property]];
53
50
  },
54
51
  };
55
52
  if (filters_list) {
@@ -59,20 +56,31 @@ export async function filterPreparation(
59
56
  // Should be fixed: modification of filters_list valuesArray
60
57
  switch (filter.input_type) {
61
58
  case "variable":
62
- const functionName =
63
- filter.input_type + "Method" + filter.input_value;
64
- const func = objectMethod[functionName];
65
- if (typeof func === "function") {
66
- filter.valuesArray = func();
67
- } else {
68
- filter.valuesArray = objectMethod.variableMethodvariable();
59
+ filter.valuesArray = [];
60
+ for(const filterValue of filter?.input_value.split(',')) {
61
+ const functionName =
62
+ filter.input_type + "Method" + filterValue;
63
+ const func = objectMethod[functionName];
64
+ if (typeof func === "function") {
65
+ if(!filter.valuesArray) {
66
+ filter.valuesArray = func();
67
+ } else {
68
+ filter.valuesArray.push(...func());
69
+ }
70
+ } else {
71
+ if(!filter.valuesArray) {
72
+ filter.valuesArray = objectMethod.variableMethodvariable(filterValue);
73
+ } else {
74
+ filter.valuesArray.push(...objectMethod.variableMethodvariable(filterValue));
75
+ }
76
+ }
69
77
  }
70
78
  filterArray.push(filter);
71
79
  break;
72
80
  case "field":
73
81
  const field_value = await fieldMethod({
74
- app_id: current_app_id,
75
- item_id: item_id,
82
+ app_id: variables.current_app_id || variables.app_id,
83
+ item_id: variables.item_id,
76
84
  field_id: filter.input_value,
77
85
  });
78
86
  if(field_value != null){
@@ -68,6 +68,28 @@ export function compiler(scheme, item, util, variables, appId) {
68
68
 
69
69
  }
70
70
 
71
+ if(scheme.offset) {
72
+ let offset;
73
+ if(scheme.use_variables_for_limit_and_offset && variables) {
74
+ offset = variables[scheme.offset];
75
+ } else {
76
+ offset = /^[0-9]+$/.test(scheme.offset) ? scheme.offset : 0;
77
+ }
78
+ filteredItems = filteredItems.slice(offset);
79
+ }
80
+
81
+ if(scheme.limit) {
82
+ let limit;
83
+ if(scheme.use_variables_for_limit_and_offset && variables) {
84
+ limit = variables[scheme.limit];
85
+ } else {
86
+ limit = /^[0-9]+$/.test(scheme.limit) || 0;
87
+ }
88
+ if(limit !== 0) {
89
+ filteredItems = filteredItems.slice(0, limit);
90
+ }
91
+ }
92
+
71
93
  const arrayOfItemsWithProperties = filteredItems.map(async (item) => {
72
94
  return getChildsPropertiesObject(scheme.childs, item, app.app_id);
73
95
  });
@@ -140,10 +162,12 @@ export function compiler(scheme, item, util, variables, appId) {
140
162
  async function getFilteredItems(filtersList, element_app_id, app_id, item_id, itemsList) {
141
163
  const modified_filters_list = await util.gudhub.prefilter(
142
164
  JSON.parse(JSON.stringify(filtersList)),
143
- element_app_id,
144
- app_id,
145
- item_id,
146
- variables
165
+ {
166
+ element_app_id,
167
+ app_id,
168
+ item_id,
169
+ ...variables
170
+ }
147
171
  );
148
172
  return util.gudhub.filter(itemsList, [...modified_filters_list, ...filtersList]);
149
173
  }
@@ -164,5 +188,5 @@ export function compiler(scheme, item, util, variables, appId) {
164
188
  ) : [...itemsList ];
165
189
  }
166
190
 
167
- return schemeCompiler(scheme, item, appId);
191
+ return schemeCompiler(scheme, item, appId, variables);
168
192
  }
@@ -39,13 +39,19 @@ export class GudHubHttpsService {
39
39
  /\?/.test(url) ? "&" : "?"
40
40
  }token=${accessToken}${convertObjToUrlParams(request.params)}`;
41
41
  }
42
-
43
- axios.get(url).then(function (response) {
42
+ axios.get(url, {
43
+ validateStatus: function (status) {
44
+ return status < 400; // Resolve only if the status code is less than 400
45
+ }
46
+ }).then(function (response) {
47
+ if(response.status != 200) {
48
+ console.error(`GUDHUB HTTP SERVICE: GET ERROR: ${response.status}`, response);
49
+ }
44
50
  // handle success
45
51
  resolve(response.data);
46
52
  })
47
53
  .catch(function (err) {
48
- console.log("ERROR -> GUDHUB HTTP SERVICE -> GET :", err.message);
54
+ console.error(`GUDHUB HTTP SERVICE: GET ERROR: ${err.response.status}\n`, err);
49
55
  console.log("Request message: ", request);
50
56
  if(err.response && err.response.data) {
51
57
  console.log('Error response data: ', err.response.data);
@@ -79,12 +85,18 @@ export class GudHubHttpsService {
79
85
  headers: request.headers || {
80
86
  "Content-Type": "application/x-www-form-urlencoded",
81
87
  },
88
+ validateStatus: function (status) {
89
+ return status < 400; // Resolve only if the status code is less than 400
90
+ }
82
91
  }
83
92
  ).then(function (response) {
93
+ if(response.status != 200) {
94
+ console.error(`GUDHUB HTTP SERVICE: POST ERROR: ${response.status}`, response);
95
+ }
84
96
  // handle success
85
97
  resolve(response.data);
86
98
  }).catch(function (error) {
87
- console.log("ERROR -> GUDHUB HTTP SERVICE -> POST :", error.message);
99
+ console.error(`GUDHUB HTTP SERVICE: POST ERROR: ${error.response.status}\n`, error);
88
100
  console.log("Request message: ", request);
89
101
  reject(error);
90
102
  });
package/GUDHUB/gudhub.js CHANGED
@@ -141,12 +141,9 @@ export class GudHub {
141
141
  }
142
142
 
143
143
  //************************* FILTERATION ****************************//
144
- prefilter(filters_list, element_app_id, app_id, item_id, variables) {
144
+ prefilter(filters_list, variables) {
145
145
  return this.util.prefilter(
146
146
  filters_list,
147
- element_app_id,
148
- app_id,
149
- item_id,
150
147
  variables
151
148
  );
152
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.1.71",
3
+ "version": "1.1.73",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {