Skip to content

Commit

Permalink
Fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtisassad committed Aug 19, 2024
1 parent 943e588 commit c20a1a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
25 changes: 12 additions & 13 deletions libs/model/src/community/CreateGroup.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,19 @@ export function CreateGroup(): Command<typeof schemas.CreateGroup> {
{ transaction },
);
if (topicsToAssociate.length > 0) {
const createPermissionsPromises = topicsToAssociate.map((topic) => {
return models.GroupPermission.create(
{
group_id: group.id,
topic_id: topic.id,
allowed_actions: Object.values(ForumActionsEnum),
},
{
transaction,
},
);
});
const permissions = topicsToAssociate.map((topic) => ({
group_id: group.id,
topic_id: topic.id,
allowed_actions: this.models.sequelize.literal(
`ARRAY[${Object.values(ForumActionsEnum)
.map((value) => `'${value}'`)
.join(', ')}]::"enum_GroupPermissions_allowed_actions"[]`,
),
}));

await Promise.all(createPermissionsPromises);
await models.GroupPermission.bulkCreate(permissions, {
transaction,
});
}
return group.toJSON();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AppError } from '@hicommonwealth/core';
import {
CommunityAttributes,
GroupAttributes,
models,
UserInstance,
} from '@hicommonwealth/model';
import { ForumActionsEnum, GroupMetadata } from '@hicommonwealth/schemas';
Expand Down Expand Up @@ -116,20 +117,17 @@ export async function __createGroup(
{ transaction: t },
);
if (topicsToAssociate.length > 0) {
const createPermissionsPromises = topicsToAssociate.map((topic) => {
return this.models.GroupPermission.create(
{
group_id: group.id,
topic_id: topic.id,
allowed_actions: Object.values(ForumActionsEnum),
},
{
transaction: t,
},
);
});
const permissions = topicsToAssociate.map((topic) => ({
group_id: group.id,
topic_id: topic.id,
allowed_actions: this.models.sequelize.literal(
`ARRAY[${Object.values(ForumActionsEnum)
.map((value) => `'${value}'`)
.join(', ')}]::"enum_GroupPermissions_allowed_actions"[]`,
),
}));

await Promise.all(createPermissionsPromises);
await models.GroupPermission.bulkCreate(permissions, { transaction: t });
}
return group.toJSON();
};
Expand Down

0 comments on commit c20a1a7

Please sign in to comment.