This commit is contained in:
2026-01-08 21:36:15 +01:00
parent 05cf3bafd2
commit d689df0270
23 changed files with 25233 additions and 88 deletions

View File

@@ -1,4 +1,4 @@
import { Body, Controller, Delete, Get, HttpCode, Param, Patch, Post, Inject, ValidationPipe, Query } from '@nestjs/common';
import { Body, Controller, Delete, Get, HttpCode, Param, Patch, Post, Inject, ValidationPipe, Query, NotFoundException, UnauthorizedException, BadRequestException } from '@nestjs/common';
import { ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Public } from '../auth/Public';
import { LeagueService } from './LeagueService';
@@ -63,6 +63,22 @@ export class LeagueController {
return this.leagueService.getAllLeaguesWithCapacity();
}
@Public()
@Get('all')
@ApiOperation({ summary: 'Get all leagues (alias for all-with-capacity)' })
@ApiResponse({ status: 200, description: 'List of all leagues', type: AllLeaguesWithCapacityDTO })
async getAllLeagues(): Promise<AllLeaguesWithCapacityDTO> {
return this.leagueService.getAllLeaguesWithCapacity();
}
@Public()
@Get('available')
@ApiOperation({ summary: 'Get available leagues (alias for all-with-capacity)' })
@ApiResponse({ status: 200, description: 'List of available leagues', type: AllLeaguesWithCapacityDTO })
async getAvailableLeagues(): Promise<AllLeaguesWithCapacityDTO> {
return this.leagueService.getAllLeaguesWithCapacity();
}
@Public()
@Get('all-with-capacity-and-scoring')
@ApiOperation({ summary: 'Get all leagues with capacity and scoring information' })
@@ -148,6 +164,21 @@ export class LeagueController {
return this.leagueService.updateLeagueMemberRole(leagueId, targetDriverId, input);
}
@Public()
@Get(':leagueId')
@ApiOperation({ summary: 'Get league by ID' })
@ApiResponse({ status: 200, description: 'League data', type: LeagueOwnerSummaryDTO })
@ApiResponse({ status: 404, description: 'League not found' })
async getLeague(@Param('leagueId') leagueId: string): Promise<LeagueOwnerSummaryDTO> {
try {
// For now, return basic league info - the service will handle 404
const query: GetLeagueOwnerSummaryQueryDTO = { ownerId: 'unknown', leagueId };
return await this.leagueService.getLeagueOwnerSummary(query);
} catch (error) {
throw new NotFoundException('League not found');
}
}
@Public()
@Get(':leagueId/owner-summary/:ownerId')
@ApiOperation({ summary: 'Get owner summary for a league' })
@@ -458,8 +489,25 @@ export class LeagueController {
@Post(':leagueId/join')
@ApiOperation({ summary: 'Join a league (actor derived from session)' })
@ApiResponse({ status: 200, description: 'Joined league successfully' })
@ApiResponse({ status: 401, description: 'Unauthorized - no session' })
@ApiResponse({ status: 400, description: 'Invalid league ID or other validation error' })
async joinLeague(@Param('leagueId') leagueId: string) {
return this.leagueService.joinLeague(leagueId);
try {
return await this.leagueService.joinLeague(leagueId);
} catch (error) {
// Handle authentication errors
if (error instanceof Error && error.message === 'Unauthorized') {
throw new UnauthorizedException('Authentication required');
}
// Handle database/repository errors (invalid UUID, etc.)
if (error instanceof Error && (error.message.includes('REPOSITORY_ERROR') || error.message.includes('invalid input syntax'))) {
throw new BadRequestException('Invalid league ID');
}
// Re-throw other errors
throw error;
}
}
@Post(':leagueId/transfer-ownership')
@@ -514,4 +562,4 @@ export class LeagueController {
): Promise<WithdrawFromLeagueWalletOutputDTO> {
return this.leagueService.withdrawFromLeagueWallet(leagueId, input);
}
}
}