Skip to content

Commit

Permalink
fix(ccu): remove ccu crash app if ccu not found
Browse files Browse the repository at this point in the history
  • Loading branch information
lambiengcode committed Apr 27, 2024
1 parent 032b39e commit 9aae2cc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/features/auth/auth.proto.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ export class AuthGrpcController implements auth.AuthService {
@GrpcMethod('AuthService', 'removeCCU')
removeCCU(data: auth.RemoveCCURequest): Observable<auth.StatusResponse> {
try {
this.ccuService.findOne({ socketId: data.socketId }).then((ccu) => {
this.ccuService.remove(ccu);
});
this.ccuService.removeCCU(data.socketId);

const response: auth.StatusResponse = {
succeed: true,
Expand Down
24 changes: 22 additions & 2 deletions src/features/auth/ccu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,35 @@ export class CCUService {
);
}

async removeCCU(socketId: string) {
const participantsToDelete = await this.participantRepository.find({
where: { ccu: { socketId: socketId } },
});

if (participantsToDelete) {
await this.participantRepository.remove(participantsToDelete);
}

const ccusToDelete = await this.ccuRepository.find({ where: { socketId } });

if (ccusToDelete) {
await this.ccuRepository.remove(ccusToDelete);
}
}

async destroyByPodName(podName: string) {
const participantsToDelete = await this.participantRepository.find({
where: { ccu: { podName } },
});

await this.participantRepository.remove(participantsToDelete);
if (participantsToDelete) {
await this.participantRepository.remove(participantsToDelete);
}

const ccusToDelete = await this.ccuRepository.find({ where: { podName } });

await this.ccuRepository.remove(ccusToDelete);
if (ccusToDelete) {
await this.ccuRepository.remove(ccusToDelete);
}
}
}
8 changes: 7 additions & 1 deletion src/features/meeting/meeting.proto.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller } from '@nestjs/common';
import { BadRequestException, Controller } from '@nestjs/common';
import { GrpcMethod } from '@nestjs/microservices';
import { meeting } from 'waterbus-proto';
import { MeetingUseCases } from './meeting.usecase';
Expand All @@ -24,6 +24,12 @@ export class MeetingGrpcController implements meeting.MeetingService {
this.meetingsUseCases
.getParticipantById(participantId, socketId)
.then((participant) => {
if (!participant.ccu) {
observer.error(new BadRequestException('Participant not valid'));
observer.complete();
return;
}

const response: meeting.GetParticipantResponse = {
id: participant.id,
user: {
Expand Down
3 changes: 2 additions & 1 deletion src/features/meeting/meeting.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,9 @@ export class MeetingUseCases {
(participant) => participant.id == participantId,
);

if (indexOfParticipant == -1)
if (indexOfParticipant == -1) {
throw new NotFoundException('Participant Not Found');
}

await this.participantService.remove([
existsRoom.participants[indexOfParticipant],
Expand Down

0 comments on commit 9aae2cc

Please sign in to comment.