Skip to content

Commit b1041f9

Browse files
authored
Merge pull request #14 from vsCode-Game/fix/user
fix: getGameRoom 게임방 정보 조회시 유저 닉네임도 returun
2 parents 6e18e80 + a965f85 commit b1041f9

6 files changed

Lines changed: 24 additions & 9 deletions

File tree

src.zip

32.5 KB
Binary file not shown.

src/game/game.gateway.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ export class GameGateway
6262
);
6363

6464
const userNickname = await this.gameService.getUserNickname(userId);
65-
if (roomId) {
66-
await this.gameRoomService.leaveRoom(roomId, userId);
67-
this.server.to(roomId.toString()).emit('message', {
68-
sender: 'System',
69-
message: `${userNickname} 유저가 퇴장했습니다.`,
70-
});
71-
}
65+
// if (roomId) {
66+
// await this.gameRoomService.leaveRoom(roomId, userId);
67+
// this.server.to(roomId.toString()).emit('message', {
68+
// sender: 'System',
69+
// message: `${userNickname} 유저가 퇴장했습니다.`,
70+
// });
71+
// }
7272
}
7373

7474
// ─────────────────────────────────────────

src/gameRoom/dto/gameRoomUser.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// dto/gameRoomUser.dto.ts
22
import { ApiProperty } from '@nestjs/swagger';
3-
import { IsNumber, IsDate } from 'class-validator';
3+
import { IsNumber, IsDate, IsString } from 'class-validator';
44

55
export class GameRoomUserDto {
66
@ApiProperty({ example: 1, description: 'GameRoomUser 테이블 PK' })

src/gameRoom/gameRoom.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class GameRoomController {
8585
async createRoom(@Body() body: CreateGameRoomDto, @Req() req: any) {
8686
try {
8787
const userId = req.user.userId; // JWT에서 추출한 userId
88+
8889
return await this.gameRoomService.createRoom(body.roomName, userId);
8990
} catch (error) {
9091
throw new BadRequestException(error.message);

src/gameRoom/gameRoom.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { GameRoomService } from './gameRoom.service';
55
import { GameRoom } from './entities/gameRoom.entity';
66
import { GameRoomUser } from './entities/gameRoomUser.entity';
77
import { RedisModule } from 'src/redis/redis.module'; // RedisModule 추가
8+
import { UserModule } from 'src/user/user.module';
89

910
@Module({
1011
imports: [
1112
TypeOrmModule.forFeature([GameRoom, GameRoomUser]),
1213
RedisModule, // RedisModule 가져오기
14+
UserModule,
1315
],
1416
controllers: [GameRoomController],
1517
providers: [GameRoomService],

src/gameRoom/gameRoom.service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { InjectRepository } from '@nestjs/typeorm';
77
import { Repository } from 'typeorm';
88
import { GameRoom } from './entities/gameRoom.entity';
99
import { GameRoomUser } from './entities/gameRoomUser.entity';
10+
import { UserService } from 'src/user/user.service';
1011

1112
@Injectable()
1213
export class GameRoomService {
@@ -15,6 +16,7 @@ export class GameRoomService {
1516
private readonly gameRoomRepository: Repository<GameRoom>,
1617
@InjectRepository(GameRoomUser)
1718
private readonly gameRoomUserRepository: Repository<GameRoomUser>,
19+
private readonly userService: UserService,
1820
) {}
1921

2022
// ─────────────────────────────────────────
@@ -176,13 +178,23 @@ export class GameRoomService {
176178

177179
// DB에서 인원 목록 조회
178180
const users = await this.gameRoomUserRepository.find({ where: { roomId } });
181+
console.log(users);
182+
const usersWithNicknames = await Promise.all(
183+
users.map(async (user) => {
184+
const userData = await this.userService.findUserById(user.userId);
185+
return {
186+
...user,
187+
userNickname: userData.userNickname,
188+
};
189+
}),
190+
);
179191

180192
// (선택) 혹시 최신 인원수를 다시 덮어씌우고 싶다면:
181193
// const count = await this.gameRoomUserRepository.count({ where: { roomId } });
182194
// room.currentCount = count;
183195
// await this.gameRoomRepository.save(room);
184196

185-
return { room, users };
197+
return { room, users: usersWithNicknames };
186198
}
187199

188200
// ─────────────────────────────────────────

0 commit comments

Comments
 (0)