/** * Get all subgroups for the given group ID * @param {String} groupId the group ID * @returns {Array<String>} an array with the groups ID and the IDs of all subGroups */ async function expandWithSubGroups (groupId) { const token = await getM2MToken() const result = await axios.get(`${config.GROUPS_API_URL}/${groupId}`, { headers: { Authorization: `Bearer ${token}` }, params: { includeSubGroups: true } }) const groups = result.data || {} return [groupId, ..._.map(_.get(groups, 'subGroups', []), 'id')] }
/** * Get the "up the chain" group tree for the given group ID * @param {String} groupId the group ID * @returns {Array<String>} an array with the group ID and the IDs of all parent groups up the chain */ async function expandWithParentGroups (groupId) { const token = await getM2MToken() const result = await axios.get(`${config.GROUPS_API_URL}/${groupId}`, { headers: { Authorization: `Bearer ${token}` }, params: { includeParentGroup: true, oneLevel: false } }) const ids = [] const extractIds = (group) => { ids.push(group.id) _.each(_.get(group, 'parentGroups', []), (parent) => { extractIds(parent) }) } extractIds(result.data || {}) return ids }
const result = await axios.get(config.GROUPS_API_URL, { headers: { Authorization: `Bearer ${token}` }, params: {