@@ -194,16 +194,12 @@ router.get('/:slug', async (req, res) => {
194194router . get ( '/:slug/players' , Utils . ensureAuthenticated , async ( req , res ) => {
195195 const slug : string = req . params . slug ;
196196 const requestorSteamId = req . user ?. steam_id ;
197- let role : string = 'user' ;
198197 if ( ! requestorSteamId ) {
199198 return res . status ( 401 ) . json ( { error : 'Unauthorized: Steam ID missing.' } ) ;
200199 }
201-
202- if ( req . user ?. admin ) role = 'admin' ;
203- else if ( req . user ?. super_admin ) role = 'super_admin' ;
204200
205201 try {
206- const users = await QueueService . listUsersInQueue ( slug , role , requestorSteamId ) ;
202+ const users = await QueueService . listUsersInQueue ( slug ) ;
207203 res . status ( 200 ) . json ( users ) ;
208204 } catch ( error ) {
209205 console . error ( 'Error listing users in queue:' , error ) ;
@@ -256,7 +252,7 @@ router.post('/', Utils.ensureAuthenticated, async (req, res) => {
256252 const isPrivate : boolean = req . body [ 0 ] . private ? true : false ;
257253
258254 try {
259- const descriptor = await QueueService . createQueue ( req . user ?. steam_id ! , maxPlayers , isPrivate ) ;
255+ const descriptor = await QueueService . createQueue ( req . user ?. steam_id ! , req . user ?. name ! , maxPlayers , isPrivate ) ;
260256 res . json ( { message : "Queue created successfully!" , url : `${ config . get ( "server.apiURL" ) } /queue/${ descriptor . name } ` } ) ;
261257 } catch ( error ) {
262258 console . error ( 'Error creating queue:' , error ) ;
@@ -326,20 +322,25 @@ router.post('/', Utils.ensureAuthenticated, async (req, res) => {
326322 */
327323router . put ( '/:slug' , Utils . ensureAuthenticated , async ( req , res ) => {
328324 const slug : string = req . params . slug ;
329- const action : string = req . body [ 0 ] . action ? req . body [ 0 ] . action : 'join' ;
325+ const action : string = req . body [ 0 ] ? .action ? req . body [ 0 ] . action : 'join' ;
330326
331327 try {
332328 let currentQueueCount : number = await QueueService . getCurrentQueuePlayerCount ( slug ) ;
333329 let maxQueueCount : number = await QueueService . getCurrentQueueMaxCount ( slug ) ;
334330 if ( action === 'join' ) {
335- await QueueService . addUserToQueue ( slug , req . user ?. steam_id ! ) ;
331+ await QueueService . addUserToQueue ( slug , req . user ?. steam_id ! , req . user ?. name ! ) ;
332+ currentQueueCount ++ ;
336333 if ( currentQueueCount == maxQueueCount ) {
337334 // Queue is full — create teams and persist them.
335+ // Create match from queue
338336 try {
339- const result = await QueueService . createTeamsFromQueue ( slug ) ;
340- return res . status ( 200 ) . json ( { success : true , teams : result . teams } ) ;
337+ const teamIds = await QueueService . createTeamsFromQueue ( slug ) ;
338+ console . log ( 'Created teams from full queue:' , teamIds ) ;
339+ const matchId = await QueueService . createMatchFromQueue ( slug , teamIds ) ;
340+ return res . status ( 200 ) . json ( { success : true , matchId : matchId , message : 'Match created successfully from full queue.' } ) ;
341341 } catch ( err ) {
342- console . error ( 'Error creating teams from queue:' , err ) ;
342+ console . error ( 'Error creating teams or match from queue:' , err ) ;
343+ res . status ( 500 ) . json ( { error : `Failed to create teams or match from queue.` } ) ;
343344 // Fall through to return success=true but without teams
344345 }
345346 }
0 commit comments