@@ -2,7 +2,7 @@ import { HttpStatus, Injectable, InternalServerErrorException, NotFoundException
22import { InviteDto } from './dto/invite.dto' ;
33import { Invite } from './entities/invite.entity' ;
44import { Organisation } from '@modules/organisations/entities/organisations.entity' ;
5- import { Repository } from 'typeorm' ;
5+ import { Repository , EntityManager } from 'typeorm' ;
66import { InjectRepository } from '@nestjs/typeorm' ;
77import { v4 as uuidv4 } from 'uuid' ;
88import { AcceptInviteDto } from './dto/accept-invite.dto' ;
@@ -24,7 +24,8 @@ export class InviteService {
2424 private readonly mailerService : MailerService ,
2525 private readonly emailService : EmailService ,
2626 private readonly configService : ConfigService ,
27- private readonly OrganisationService : OrganisationsService
27+ private readonly OrganisationService : OrganisationsService ,
28+ private readonly entityManager : EntityManager
2829 ) { }
2930
3031 async getPendingInvites ( ) : Promise < { message : string ; data : InviteDto [ ] } > {
@@ -127,17 +128,23 @@ export class InviteService {
127128 throw new CustomHttpException ( SYS_MSG . USER_NOT_REGISTERED , HttpStatus . NOT_FOUND ) ;
128129 }
129130
130- const response = await this . OrganisationService . addOrganisationMember ( invite . organisation . id , {
131- user_id : user . id ,
131+ return await this . entityManager . transaction ( async transactionalEntityManager => {
132+ const response = await this . OrganisationService . addOrganisationMember (
133+ invite . organisation . id ,
134+ {
135+ user_id : user . id ,
136+ } ,
137+ transactionalEntityManager
138+ ) ;
139+
140+ if ( response . status === 'success' ) {
141+ invite . isAccepted = true ;
142+ await transactionalEntityManager . save ( invite ) ;
143+ return response ;
144+ } else {
145+ throw new CustomHttpException ( SYS_MSG . MEMBER_NOT_ADDED , HttpStatus . INTERNAL_SERVER_ERROR ) ;
146+ }
132147 } ) ;
133-
134- if ( response . status === 'success' ) {
135- invite . isAccepted = true ;
136- await this . inviteRepository . save ( invite ) ;
137- return response ;
138- } else {
139- throw new CustomHttpException ( SYS_MSG . MEMBER_NOT_ADDED , HttpStatus . INTERNAL_SERVER_ERROR ) ;
140- }
141148 }
142149
143150 async sendInvitations ( createInvitationDto : CreateInvitationDto ) : Promise < any > {
0 commit comments