Skip to content

Commit 9540c03

Browse files
committed
Add recursive subgroup querying
1 parent ff86366 commit 9540c03

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/models/owner.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,29 @@ class owner extends Base {
5757
this.get(`groups`)
5858
.then(groups => {
5959
if (groups.body.length === 0) return resolve();
60-
let filtered = groups.body.filter(u => this.groups.map(g => g.id).indexOf(u.parent_id) !== -1);
60+
61+
let filtered = this._filterGroupsByParents(groups.body, this.groups.map(g => g.id));
6162
if (filtered.length === 0) return resolve();
63+
6264
this.groups = this.groups.concat(filtered);
6365
resolve();
6466
})
6567
.catch(e => reject(e));
6668
});
6769
}
6870

71+
_filterGroupsByParents(groups, parents) {
72+
let filtered = groups.filter(group => {
73+
return parents.indexOf(group.parent_id) !== -1;
74+
});
75+
76+
if (filtered.length !== 0) {
77+
filtered = filtered.concat(this._filterGroupsByParents(groups, filtered.map(g => g.id)));
78+
}
79+
80+
return filtered;
81+
}
82+
6983
// /**
7084
// * query and set the user
7185
// * @returns {Promise}

0 commit comments

Comments
 (0)