bkper-js 1.35.0 → 1.35.1
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/index.d.ts +3 -0
- package/lib/model/Book.js +2 -0
- package/lib/model/Group.js +26 -7
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1853,6 +1853,8 @@ export declare class Group {
|
|
|
1853
1853
|
* @returns An array of child Groups.
|
|
1854
1854
|
*/
|
|
1855
1855
|
getChildren(): Group[];
|
|
1856
|
+
|
|
1857
|
+
|
|
1856
1858
|
/**
|
|
1857
1859
|
* Retrieves all descendant Groups of the current Group.
|
|
1858
1860
|
*
|
|
@@ -1905,6 +1907,7 @@ export declare class Group {
|
|
|
1905
1907
|
|
|
1906
1908
|
|
|
1907
1909
|
|
|
1910
|
+
|
|
1908
1911
|
/**
|
|
1909
1912
|
* @returns True if this group has any account in it
|
|
1910
1913
|
*/
|
package/lib/model/Book.js
CHANGED
|
@@ -585,12 +585,14 @@ export class Book {
|
|
|
585
585
|
if (id) {
|
|
586
586
|
this.idGroupMap.set(id, group);
|
|
587
587
|
}
|
|
588
|
+
group.buildGroupTree(this.idGroupMap);
|
|
588
589
|
}
|
|
589
590
|
}
|
|
590
591
|
/** @internal */
|
|
591
592
|
removeGroupCache(group) {
|
|
592
593
|
if (this.idGroupMap) {
|
|
593
594
|
this.idGroupMap.delete(group.getId() || '');
|
|
595
|
+
group.destroyGroupTree(this.idGroupMap);
|
|
594
596
|
}
|
|
595
597
|
}
|
|
596
598
|
/** @internal */
|
package/lib/model/Group.js
CHANGED
|
@@ -21,7 +21,7 @@ import { Account } from './Account.js';
|
|
|
21
21
|
*/
|
|
22
22
|
export class Group {
|
|
23
23
|
constructor(book, payload) {
|
|
24
|
-
this.children =
|
|
24
|
+
this.children = new Map();
|
|
25
25
|
this.book = book;
|
|
26
26
|
this.payload = payload || {
|
|
27
27
|
createdAt: `${Date.now()}`
|
|
@@ -214,7 +214,21 @@ export class Group {
|
|
|
214
214
|
* @returns An array of child Groups.
|
|
215
215
|
*/
|
|
216
216
|
getChildren() {
|
|
217
|
-
return this.children || [];
|
|
217
|
+
return Array.from(this.children.values()) || [];
|
|
218
|
+
}
|
|
219
|
+
/** @internal */
|
|
220
|
+
addChild(child) {
|
|
221
|
+
const id = child.getId();
|
|
222
|
+
if (id) {
|
|
223
|
+
this.children.set(id, child);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/** @internal */
|
|
227
|
+
removeChild(child) {
|
|
228
|
+
const id = child.getId();
|
|
229
|
+
if (id) {
|
|
230
|
+
this.children.delete(id);
|
|
231
|
+
}
|
|
218
232
|
}
|
|
219
233
|
/**
|
|
220
234
|
* Retrieves all descendant Groups of the current Group.
|
|
@@ -321,7 +335,16 @@ export class Group {
|
|
|
321
335
|
const parentGroup = groupsMap.get(this.payload.parent.id || "");
|
|
322
336
|
if (parentGroup) {
|
|
323
337
|
this.parent = parentGroup;
|
|
324
|
-
parentGroup.
|
|
338
|
+
parentGroup.addChild(this);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/** @internal */
|
|
343
|
+
destroyGroupTree(groupsMap) {
|
|
344
|
+
if (this.payload.parent) {
|
|
345
|
+
const parentGroup = groupsMap.get(this.payload.parent.id || "");
|
|
346
|
+
if (parentGroup) {
|
|
347
|
+
parentGroup.removeChild(this);
|
|
325
348
|
}
|
|
326
349
|
}
|
|
327
350
|
}
|
|
@@ -356,10 +379,6 @@ export class Group {
|
|
|
356
379
|
return __awaiter(this, void 0, void 0, function* () {
|
|
357
380
|
this.payload = yield GroupService.createGroup(this.book.getId(), this.payload);
|
|
358
381
|
this.book.updateGroupCache(this);
|
|
359
|
-
const bookGroupsMap = this.book.getGroupsMap();
|
|
360
|
-
if (bookGroupsMap) {
|
|
361
|
-
this.buildGroupTree(bookGroupsMap);
|
|
362
|
-
}
|
|
363
382
|
return this;
|
|
364
383
|
});
|
|
365
384
|
}
|