@@ -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