@@ -140,6 +140,45 @@ export class GameService {
140140 return `${ adj } ${ noun } ` ;
141141 }
142142
143+ async testJoinRoom ( roomId : string , playerId : string ) {
144+ const [ room , roomSettings , players ] = await Promise . all ( [
145+ this . gameRepository . getRoom ( roomId ) ,
146+ this . gameRepository . getRoomSettings ( roomId ) ,
147+ this . gameRepository . getRoomPlayers ( roomId ) ,
148+ ] ) ;
149+
150+ if ( ! room ) throw new RoomNotFoundException ( ) ;
151+ if ( room . status === RoomStatus . GUESSING || room . status === RoomStatus . DRAWING ) {
152+ throw new GameAlreadyStartedException ( 'Cannot join room while game is in progress' ) ;
153+ }
154+ if ( ! roomSettings ) throw new RoomNotFoundException ( 'Room settings not found' ) ;
155+ if ( players . length >= roomSettings . maxPlayers ) {
156+ throw new RoomFullException ( 'Room is full' ) ;
157+ }
158+
159+ const nickname = this . generateNickname ( ) ;
160+ const player : Player = {
161+ playerId,
162+ role : null ,
163+ status : PlayerStatus . NOT_PLAYING ,
164+ nickname,
165+ profileImage : `https://api.dicebear.com/9.x/pixel-art/svg?seed=${ nickname } ` ,
166+ score : 0 ,
167+ } ;
168+
169+ const isFirstPlayer = players . length === 0 ;
170+ if ( isFirstPlayer ) {
171+ room . hostId = playerId ;
172+ await this . gameRepository . updateRoom ( roomId , { hostId : playerId } ) ;
173+ }
174+
175+ await this . gameRepository . addPlayerToRoom ( roomId , playerId , player ) ;
176+
177+ const updatedPlayers = [ player , ...players ] . reverse ( ) ;
178+
179+ return { room, roomSettings, player, players : updatedPlayers } ;
180+ }
181+
143182 async reconnect ( roomId : string , playerId : string ) {
144183 const [ room , roomSettings , players ] = await Promise . all ( [
145184 this . gameRepository . getRoom ( roomId ) ,
0 commit comments