Skip to content

Commit 089815a

Browse files
yoganandanessgithub-actions[bot]
authored andcommitted
fixed comments
1 parent 014fbe4 commit 089815a

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

apps/backend/src/eventHandlers/email/essEmailHandler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export async function essEmailHandler(event: ApplicationEvent) {
6464
switch (event.type) {
6565
case Event.PROPOSAL_CO_PROPOSER_INVITE_ACCEPTED: {
6666
const invite: Invite = event.invite;
67+
const loggedInUserId = event.loggedInUserId;
68+
69+
if (!loggedInUserId) return;
6770

6871
const coProposerClaims = await coProposerDataSource.findByInviteId(
6972
invite.id
@@ -101,9 +104,7 @@ export async function essEmailHandler(event: ApplicationEvent) {
101104
return;
102105
}
103106

104-
const claimer = await userDataSource.getUser(
105-
invite.claimedByUserId as number
106-
);
107+
const claimer = await userDataSource.getUser(loggedInUserId);
107108
if (!claimer) {
108109
logger.logError(
109110
'No claimer found when trying to send invite accepted email',

apps/backend/src/mutations/InviteMutations.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export default class InviteMutations {
5757
agent: UserWithRole | null,
5858
code: string
5959
): Promise<Invite | Rejection> {
60+
if (!agent) {
61+
return rejection('User not found', { invite: code });
62+
}
6063
const invite = await this.inviteDataSource.findByCode(code);
6164
if (invite === null) {
6265
return rejection('Invite code not found', { invite: code });
@@ -69,28 +72,30 @@ export default class InviteMutations {
6972
return rejection('Invite code has expired', { invite: code });
7073
}
7174

75+
await this.processAcceptedRoleClaims(agent.id, invite);
76+
await this.processAcceptedCoProposerClaims(agent.id, invite);
77+
await this.processAcceptedVisitRegistrationClaims(agent.id, invite);
78+
7279
const updatedInvite = await this.inviteDataSource.update({
7380
id: invite.id,
7481
claimedAt: new Date(),
7582
claimedByUserId: agent!.id,
7683
});
7784

78-
await this.processAcceptedRoleClaims(agent!.id, updatedInvite);
79-
await this.processAcceptedCoProposerClaims(agent!.id, updatedInvite);
80-
await this.processAcceptedVisitRegistrationClaims(agent!.id, updatedInvite);
81-
8285
return updatedInvite;
8386
}
8487

8588
@Authorized([Roles.USER])
8689
async acceptCoProposerInvite(agent: UserWithRole | null, proposalId: string) {
90+
if (!agent) {
91+
return rejection('User not found', { proposalId });
92+
}
93+
8794
const proposal = await this.proposalDataSource.getProposalById(proposalId);
8895
if (!proposal) {
8996
return rejection('Proposal not found', { proposalId });
9097
}
91-
if (!agent) {
92-
return rejection('User not found', { proposalId });
93-
}
98+
9499
const [invite] = await this.inviteDataSource.getCoProposerInvites({
95100
proposalPk: proposal.primaryKey,
96101
email: agent.email,
@@ -101,15 +106,15 @@ export default class InviteMutations {
101106
return rejection('Invite not found', { proposalId });
102107
}
103108

109+
await this.processAcceptedRoleClaims(agent.id, invite);
110+
await this.processAcceptedCoProposerClaims(agent.id, invite);
111+
104112
const updatedInvite = await this.inviteDataSource.update({
105113
id: invite.id,
106114
claimedAt: new Date(),
107115
claimedByUserId: agent.id,
108116
});
109117

110-
await this.processAcceptedRoleClaims(agent.id, updatedInvite);
111-
await this.processAcceptedCoProposerClaims(agent.id, updatedInvite);
112-
113118
return updatedInvite;
114119
}
115120

0 commit comments

Comments
 (0)