diff --git a/src.zip b/src.zip new file mode 100644 index 0000000..3d5ea51 Binary files /dev/null and b/src.zip differ diff --git a/src/game/game.gateway.ts b/src/game/game.gateway.ts index bc75d50..16829f8 100644 --- a/src/game/game.gateway.ts +++ b/src/game/game.gateway.ts @@ -62,13 +62,13 @@ export class GameGateway ); const userNickname = await this.gameService.getUserNickname(userId); - if (roomId) { - await this.gameRoomService.leaveRoom(roomId, userId); - this.server.to(roomId.toString()).emit('message', { - sender: 'System', - message: `${userNickname} 유저가 퇴장했습니다.`, - }); - } + // if (roomId) { + // await this.gameRoomService.leaveRoom(roomId, userId); + // this.server.to(roomId.toString()).emit('message', { + // sender: 'System', + // message: `${userNickname} 유저가 퇴장했습니다.`, + // }); + // } } // ───────────────────────────────────────── diff --git a/src/gameRoom/dto/gameRoomUser.dto.ts b/src/gameRoom/dto/gameRoomUser.dto.ts index cfb8f60..0ae753c 100644 --- a/src/gameRoom/dto/gameRoomUser.dto.ts +++ b/src/gameRoom/dto/gameRoomUser.dto.ts @@ -1,6 +1,6 @@ // dto/gameRoomUser.dto.ts import { ApiProperty } from '@nestjs/swagger'; -import { IsNumber, IsDate } from 'class-validator'; +import { IsNumber, IsDate, IsString } from 'class-validator'; export class GameRoomUserDto { @ApiProperty({ example: 1, description: 'GameRoomUser 테이블 PK' }) diff --git a/src/gameRoom/gameRoom.controller.ts b/src/gameRoom/gameRoom.controller.ts index e258297..009d2b3 100644 --- a/src/gameRoom/gameRoom.controller.ts +++ b/src/gameRoom/gameRoom.controller.ts @@ -85,6 +85,7 @@ export class GameRoomController { async createRoom(@Body() body: CreateGameRoomDto, @Req() req: any) { try { const userId = req.user.userId; // JWT에서 추출한 userId + return await this.gameRoomService.createRoom(body.roomName, userId); } catch (error) { throw new BadRequestException(error.message); diff --git a/src/gameRoom/gameRoom.module.ts b/src/gameRoom/gameRoom.module.ts index 516917d..4c00b4d 100644 --- a/src/gameRoom/gameRoom.module.ts +++ b/src/gameRoom/gameRoom.module.ts @@ -5,11 +5,13 @@ import { GameRoomService } from './gameRoom.service'; import { GameRoom } from './entities/gameRoom.entity'; import { GameRoomUser } from './entities/gameRoomUser.entity'; import { RedisModule } from 'src/redis/redis.module'; // RedisModule 추가 +import { UserModule } from 'src/user/user.module'; @Module({ imports: [ TypeOrmModule.forFeature([GameRoom, GameRoomUser]), RedisModule, // RedisModule 가져오기 + UserModule, ], controllers: [GameRoomController], providers: [GameRoomService], diff --git a/src/gameRoom/gameRoom.service.ts b/src/gameRoom/gameRoom.service.ts index 5c83eb6..a3ffe69 100644 --- a/src/gameRoom/gameRoom.service.ts +++ b/src/gameRoom/gameRoom.service.ts @@ -7,6 +7,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { GameRoom } from './entities/gameRoom.entity'; import { GameRoomUser } from './entities/gameRoomUser.entity'; +import { UserService } from 'src/user/user.service'; @Injectable() export class GameRoomService { @@ -15,6 +16,7 @@ export class GameRoomService { private readonly gameRoomRepository: Repository, @InjectRepository(GameRoomUser) private readonly gameRoomUserRepository: Repository, + private readonly userService: UserService, ) {} // ───────────────────────────────────────── @@ -176,13 +178,23 @@ export class GameRoomService { // DB에서 인원 목록 조회 const users = await this.gameRoomUserRepository.find({ where: { roomId } }); + console.log(users); + const usersWithNicknames = await Promise.all( + users.map(async (user) => { + const userData = await this.userService.findUserById(user.userId); + return { + ...user, + userNickname: userData.userNickname, + }; + }), + ); // (선택) 혹시 최신 인원수를 다시 덮어씌우고 싶다면: // const count = await this.gameRoomUserRepository.count({ where: { roomId } }); // room.currentCount = count; // await this.gameRoomRepository.save(room); - return { room, users }; + return { room, users: usersWithNicknames }; } // ─────────────────────────────────────────