Skip to content

Commit

Permalink
Added bulk create for group topic permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
mzparacha committed Oct 17, 2024
1 parent 7fcc815 commit a2009af
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions libs/model/src/community/CreateGroup.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,19 @@ export function CreateGroup(): Command<
},
);

// add topic level interaction permissions for current group
await Promise.all(
(payload.topics || [])?.map(async (t) => {
if (group.id) {
await models.GroupPermission.create(
{
group_id: group.id,
topic_id: t.id,
allowed_actions: t.permissions,
},
{ transaction },
);
}
}),
);
if (group.id) {
// add topic level interaction permissions for current group
const groupPermissions = (payload.topics || []).map((t) => ({
group_id: group.id!,
topic_id: t.id,
allowed_actions: sequelize.literal(
`ARRAY[${t.permissions.map((p) => `'${p}'`).join(', ')}]::"enum_GroupPermissions_allowed_actions"[]`,
) as unknown as schemas.PermissionEnum[],
}));
await models.GroupPermission.bulkCreate(groupPermissions, {
transaction,
});
}
}
return group.toJSON();
},
Expand Down

0 comments on commit a2009af

Please sign in to comment.