Skip to content

Commit

Permalink
UPDATE: limit 20 member for room (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
sedeve authored Nov 15, 2023
2 parents 4651f7d + 8d89d43 commit 49e0f8d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions backend/code/src/rooms/rooms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ export class RoomsService {
where: { id: roomData.roomId },
select: { type: true, password: true },
});

const count = await this.prisma.roomMember.aggregate({
where: {
roomId: roomData.roomId,
},
_count: {
userId: true,
}
});

if (count._count.userId > 20)
throw new HttpException('Room is full', HttpStatus.BAD_REQUEST);
if (!room) throw new HttpException('room not found', HttpStatus.NOT_FOUND);
if (room.type === 'protected' && !('password' in roomData))
throw new HttpException(
Expand Down Expand Up @@ -530,6 +542,17 @@ export class RoomsService {
},
});

const count = await this.prisma.roomMember.aggregate({
where: {
roomId: memberData.roomId,
},
_count: {
userId: true,
}
});

if (count._count.userId >= 20)
throw new HttpException('Room is full', HttpStatus.BAD_REQUEST);
if (!user || !user.is_admin || user.is_banned)
throw new UnauthorizedException('You are not the admin of this Room');
if (member) throw new UnauthorizedException('User already Exist');
Expand Down

0 comments on commit 49e0f8d

Please sign in to comment.