Skip to content

Commit 9e4da71

Browse files
committed
πŸ› οΈ refactor: (BE) - create room λ©”μ„œλ“œμ—μ„œ 쀑볡 아이디 체크
1 parent 0acbce7 commit 9e4da71

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

β€Žbackend/socket/src/room/room.gateway.tsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export class RoomGateway implements OnGatewayConnection, OnGatewayDisconnect {
4242
// connection
4343

4444
@SubscribeMessage(EVENT.CREATE_ROOM)
45-
handleCreateRoom() {
46-
return this.connectionService.createRoom();
45+
handleCreateRoom(@ConnectedSocket() client: Socket) {
46+
return this.connectionService.createRoom(client);
4747
}
4848

4949
@SubscribeMessage(EVENT.ENTER_ROOM)

β€Žbackend/socket/src/room/service/connection/connection.service.tsβ€Ž

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ export class ConnectionService {
2626
* uuidλ₯Ό 기반으둜 방을 μƒμ„±ν•˜κ³  μ €μž₯ν•˜λŠ” λ©”μ„œλ“œμž…λ‹ˆλ‹€.
2727
* @returns uuid - 방의 uuid
2828
*/
29-
async createRoom() {
29+
async createRoom(client: Socket) {
30+
const exception = await this.isEnterableClient(client.data.authId);
31+
if (exception) {
32+
return exception;
33+
}
34+
3035
const defaultRoom = this.createDefaultRoom();
3136
const room = await this.roomRepository.createRoom({
3237
roomUUID: defaultRoom.roomUUID,
@@ -45,7 +50,7 @@ export class ConnectionService {
4550
async enterRoom({ client, roomUUID }: { client: Socket; roomUUID: string }) {
4651
const room = await this.roomRepository.getRoom(roomUUID);
4752

48-
const exception = await this.isEnterable({ client, room });
53+
const exception = await this.isEnterable({ authId: client.data.userId, room });
4954
if (exception) return exception;
5055

5156
const user = await this.createDefaultUser({ client, roomUUID });
@@ -66,8 +71,8 @@ export class ConnectionService {
6671
* clientκ°€ λ“€μ–΄κ°ˆ 수 μžˆλŠ”μ§€ & room이 ν˜„μž¬ λ“€μ–΄κ°ˆ 수 μžˆλŠ” 상황인지 μ²΄ν¬ν•˜λŠ” λ©”μ„œλ“œμž…λ‹ˆλ‹€.
6772
* @returns
6873
*/
69-
async isEnterable({ client, room }: { client: Socket; room: Room }) {
70-
return (await this.isEnterableClient(client)) ?? (await this.isEnterableRoom(room)) ?? null;
74+
async isEnterable({ authId, room }: { authId: string; room: Room }) {
75+
return (await this.isEnterableClient(authId)) ?? (await this.isEnterableRoom(room)) ?? null;
7176
}
7277

7378
/**
@@ -94,12 +99,12 @@ export class ConnectionService {
9499
}
95100

96101
/**
97-
* ν•΄λ‹Ή socket clientκ°€ interview에 참석할 수 μžˆλŠ”μ§€ μ²΄ν¬ν•˜λŠ” λ©”μ„œλ“œμž…λ‹ˆλ‹€.
98-
* @param client
102+
* νšŒμ›μ΄ interview에 참석할 수 μžˆλŠ”μ§€ μ²΄ν¬ν•˜λŠ” λ©”μ„œλ“œμž…λ‹ˆλ‹€.
103+
* @param authId
99104
* @returns
100105
*/
101-
async isEnterableClient(client: Socket) {
102-
const prevUser = await this.roomRepository.getUserIdByAuthId(client.data.authId);
106+
async isEnterableClient(authId: string) {
107+
const prevUser = await this.roomRepository.getUserIdByAuthId(authId);
103108
if (prevUser) {
104109
return { success: false, message: SOCKET_MESSAGE.EXIST_SAME_AUTH_ID };
105110
}

0 commit comments

Comments
Β (0)