@digione/node-custom-api 0.1.9-beta4 → 0.1.9-beta6

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": "@digione/node-custom-api",
3
- "version": "0.1.9-beta4",
3
+ "version": "0.1.9-beta6",
4
4
  "description": "Typescript node digione-api",
5
5
  "author": "Monchai Jirayupong <monchai.j@seven.co.th>",
6
6
  "license": "MIT",
package/utils/helper.d.ts CHANGED
@@ -64,7 +64,7 @@ export declare const randomRef: ({ length_digital, length_alphabet }?: {
64
64
  length_alphabet?: number;
65
65
  }) => string;
66
66
  export declare const treeToArray: (items: Array<any>, array?: Array<any>, level?: number) => Promise<any[]>;
67
- export declare const buildTree: (nodes: Array<any>, { index, field_children, json_convert, key_index, key_parent, root, to_array }?: {
67
+ export declare const buildTree: (nodes: Array<any>, { index, field_children, json_convert, key_index, key_parent, root, to_array, notfound_parent }?: {
68
68
  index?: any;
69
69
  field_children?: string;
70
70
  json_convert?: boolean;
@@ -72,6 +72,7 @@ export declare const buildTree: (nodes: Array<any>, { index, field_children, jso
72
72
  key_parent?: string;
73
73
  root?: any;
74
74
  to_array?: boolean;
75
+ notfound_parent?: boolean;
75
76
  }) => Promise<any[]>;
76
77
  export declare const expandTree: (items: Array<any>, { array, parent, level, prefix, field_index, field_children, key_value }?: {
77
78
  array?: any[];
package/utils/helper.js CHANGED
@@ -228,7 +228,7 @@ const treeToArray = (items, array = [], level = 1) => tslib_1.__awaiter(void 0,
228
228
  return array;
229
229
  });
230
230
  exports.treeToArray = treeToArray;
231
- const buildTree = (nodes, { index = undefined, field_children = "children", json_convert = false, key_index = "id", key_parent = "parent", root = undefined, to_array = false } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
231
+ const buildTree = (nodes, { index = undefined, field_children = "children", json_convert = false, key_index = "id", key_parent = "parent", root = undefined, to_array = false, notfound_parent = false } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
232
232
  if (!nodes) {
233
233
  return null;
234
234
  }
@@ -266,11 +266,16 @@ const buildTree = (nodes, { index = undefined, field_children = "children", json
266
266
  }
267
267
  }
268
268
  parent[field_children] = results;
269
+ delete children[parent[key_index]];
269
270
  }
270
271
  };
271
272
  for (let i = 0, len = roots.length; i < len; ++i) {
272
273
  findChildren(roots[i]);
273
274
  }
275
+ if (notfound_parent) {
276
+ let items = Object.keys(children).reduce((total, key) => total.concat(children[key]), []);
277
+ roots.unshift({ [key_index]: -1, [field_children]: items });
278
+ }
274
279
  if (index)
275
280
  roots = roots[0];
276
281
  if (roots && to_array) {
package/utils/stream.js CHANGED
@@ -1655,8 +1655,10 @@ class StreamUtil {
1655
1655
  }
1656
1656
  }
1657
1657
  }
1658
- let sort_order = yield field_1.FieldModel.schema(this.ref, "_").max('sort_order', { where: { stream_id: stream['id'] } });
1659
- field['sort_order'] = sort_order ? Number(sort_order + 1) : 1;
1658
+ if (typeof field['sort_order'] == "undefined") {
1659
+ let sort_order = yield field_1.FieldModel.schema(this.ref, "_").max('sort_order', { where: { stream_id: stream['id'] } });
1660
+ field['sort_order'] = sort_order ? Number(sort_order + 1) : 1;
1661
+ }
1660
1662
  if (!field['stream_id']) {
1661
1663
  field['stream_id'] = stream['id'];
1662
1664
  }