Skip to content

Commit

Permalink
add autoDelete roles if platform deleted + added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Mar 14, 2024
1 parent 3f45c86 commit b128e61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions __tests__/unit/models/platform.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ describe('Platform model', () => {
await platform.remove();
communityDoc = await Community.findById(community.id);
expect(communityDoc?.platforms).toEqual([]);
expect(communityDoc?.roles).toEqual([]);

const platformDoc = await Platform.findById(platform._id);
expect(platformDoc).toBe(null);
});
Expand Down
5 changes: 5 additions & 0 deletions src/models/schemas/Platform.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ platformSchema.pre('remove', async function (this: Document) {
const platformId = this._id;
await Community.updateOne({ platforms: platformId }, { $pull: { platforms: platformId } });
await announcementDeletion(platformId);
await Community.updateMany(
{},
{ $pull: { roles: { 'source.platformId': platformId } } },
{ multi: true }
)
});

platformSchema.post('save', async function () {
Expand Down

0 comments on commit b128e61

Please sign in to comment.