Skip to content

Commit 607b7f8

Browse files
committed
Readability improvements
1 parent d39d33e commit 607b7f8

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

  • src/management-system-v2/lib/data

src/management-system-v2/lib/data/roles.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,28 @@ export async function handleFolderRoleChanges(
8585
const parentRole = await getRoleWithMembersById(parentRoleId, ability, false, trx);
8686
if (!parentRole) throw new Error('The role to update does not exist');
8787

88-
await asyncForEach(toRemove, async (id) => {
89-
await deleteRole(id, ability, trx);
90-
});
91-
92-
await asyncForEach(toUpdate, async ({ roleId, permissions }) => {
93-
await _updateRole(roleId, { permissions }, ability, trx);
94-
});
95-
96-
await asyncForEach(toAdd, async (input) => {
97-
const added = await _addRole(
98-
{ ...input, expiration: parentRole.expiration },
99-
ability,
100-
trx,
101-
true,
102-
);
103-
104-
const roleMappings = parentRole.members.map(({ id }) => ({
105-
environmentId,
106-
roleId: added.id,
107-
userId: id,
108-
}));
109-
110-
await addRoleMappings(roleMappings, ability, trx);
111-
});
88+
await Promise.all([
89+
...toRemove.map((id) => deleteRole(id, ability, trx)),
90+
...toUpdate.map(({ roleId, permissions }) =>
91+
_updateRole(roleId, { permissions }, ability, trx),
92+
),
93+
...toAdd.map(async (input) => {
94+
const added = await _addRole(
95+
{ ...input, expiration: parentRole.expiration },
96+
ability,
97+
trx,
98+
true,
99+
);
100+
101+
const roleMappings = parentRole.members.map(({ id }) => ({
102+
environmentId,
103+
roleId: added.id,
104+
userId: id,
105+
}));
106+
107+
await addRoleMappings(roleMappings, ability, trx);
108+
}),
109+
]);
112110
});
113111
} catch (e) {
114112
if (e instanceof UnauthorizedError) {

0 commit comments

Comments
 (0)