I want to improve my code. It’s simple javascript code where I’m fetching some data from gitlab API and I want to get gitlab groups and their members, then I want to for each member display his groups.
let accounts = []
let subGroups = await api.getSubgroups();
subGroups = subGroups.map((group) => {
const { id, name, full_path } = group;
return {
id,
name,
full_path
}
})
subGroups = subGroups.map(async (group) => {
const { id } = group;
const groupMembers = await api.getGroupMembers(id);
return { group_id: id, groupMembers };
});
subGroups = await Promise.all(subGroups);
const map = subGroups.forEach((group) => {
group.groupMembers.forEach((member) => {
accounts.push(member)
})
})
I want first get the list of groups and members of group. Then make array of distinct people and then give them their group.
Please how can I remove nested foreach, is it even possible? And also I want to ask how to get only neccessary properties of member (like only name and id) to accounts array