Skip to content

Commit

Permalink
fix : stop game
Browse files Browse the repository at this point in the history
  • Loading branch information
iqeq1945 committed Dec 3, 2024
1 parent 8704cf4 commit a1be2ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/room/room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class RoomService {

async findById(id: string): Promise<Room> {
try {
let room = await this.prisma.room.findUnique({
return await this.prisma.room.findUnique({
where: { id },
include: {
users: {
Expand All @@ -102,10 +102,6 @@ export class RoomService {
},
},
});
if (room.users.length === 1 && room.start) {
room = await this.setStart(room.id, false);
}
return room;
} catch (error) {
if (error instanceof NotFoundException) throw error;
throw new BadRequestException('방을 찾는 중 오류가 발생했습니다.');
Expand Down
9 changes: 5 additions & 4 deletions src/socket/socket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,12 @@ export class SocketGateway
@SubscribeMessage('start')
async handleStart(@MessageBody() roomId: string) {
try {
const roomInfo = await this.socketService.setStart(roomId, true);
this.roomInfo[roomId] = await this.socketService.setStart(roomId, true);
this.game[roomId].users = [];
this.server
.to(roomId)
.emit('start', { roomInfo, game: this.game[roomId] });
this.server.to(roomId).emit('start', {
roomInfo: this.roomInfo[roomId],
game: this.game[roomId],
});
} catch (error) {
this.logger.error(`Start game error - Room: ${roomId}`, error.stack);
this.server
Expand Down

0 comments on commit a1be2ac

Please sign in to comment.