Skip to content

Commit

Permalink
feat(server): send invite notification
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Feb 17, 2025
1 parent e6262b2 commit 8401fda
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/backend/server/src/core/notification/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Injectable } from '@nestjs/common';

import { OnEvent } from '../../base';
import { Models } from '../../models';
import { NotificationService } from './service';

@Injectable()
export class NotificationEvents {
constructor(
private readonly models: Models,
private readonly service: NotificationService
) {}

@OnEvent('workspace.members.invited')
async onWorkspaceMemberInvited({
inviterId,
inviteId,
}: Events['workspace.members.invited']) {
const invite = await this.models.workspace.getMemberInvitation(inviteId);
if (!invite) {
return;
}
// TODO(@fengmk2): pass permission to createInvite
await this.service.createInvite({
workspaceId: invite.workspaceId,
userId: invite.userId,
createdBy: inviterId,
});
}
}
4 changes: 4 additions & 0 deletions packages/backend/server/src/core/workspaces/resolvers/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ export class TeamWorkspaceResolver {
permission,
});
}
this.event.emit('workspace.members.invited', {
inviterId: user.id,
inviteId: result,
});
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ export class WorkspaceResolver {
);
}
}
this.event.emit('workspace.members.invited', {
inviterId: user.id,
inviteId,
});
return inviteId;
} catch (e) {
// pass through user friendly error
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/server/src/models/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ declare global {
to: string;
workspaceId: string;
};
'workspace.members.invited': {
inviterId: string;
inviteId: string;
};
'workspace.members.updated': {
workspaceId: string;
count: number;
Expand Down

0 comments on commit 8401fda

Please sign in to comment.