refactor api modules

This commit is contained in:
2025-12-22 19:17:33 +01:00
parent c90b2166c1
commit 1333f5e907
100 changed files with 2226 additions and 1936 deletions

View File

@@ -8,7 +8,7 @@ import { GetTeamMembersOutputDTO } from './dtos/GetTeamMembersOutputDTO';
import { GetTeamJoinRequestsOutputDTO } from './dtos/GetTeamJoinRequestsOutputDTO';
import { CreateTeamInputDTO } from './dtos/CreateTeamInputDTO';
import { CreateTeamOutputDTO } from './dtos/CreateTeamOutputDTO';
import { UpdateTeamInputDTO } from './dtos/UpdateTeamInputDTO';
import { UpdateTeamInput } from './dtos/TeamDto';
import { UpdateTeamOutputDTO } from './dtos/UpdateTeamOutputDTO';
import { GetDriverTeamOutputDTO } from './dtos/GetDriverTeamOutputDTO';
import { GetTeamMembershipOutputDTO } from './dtos/GetTeamMembershipOutputDTO';
@@ -22,8 +22,7 @@ export class TeamController {
@ApiOperation({ summary: 'Get all teams' })
@ApiResponse({ status: 200, description: 'List of all teams', type: GetAllTeamsOutputDTO })
async getAll(): Promise<GetAllTeamsOutputDTO> {
const presenter = await this.teamService.getAll();
return presenter.responseModel;
return await this.teamService.getAll();
}
@Get(':teamId')
@@ -31,43 +30,38 @@ export class TeamController {
@ApiResponse({ status: 200, description: 'Team details', type: GetTeamDetailsOutputDTO })
@ApiResponse({ status: 404, description: 'Team not found' })
async getDetails(@Param('teamId') teamId: string, @Req() req: Request): Promise<GetTeamDetailsOutputDTO | null> {
const userId = req['user']?.userId;
const presenter = await this.teamService.getDetails(teamId, userId);
return presenter.getResponseModel();
const userId = (req as any)['user']?.userId;
return await this.teamService.getDetails(teamId, userId);
}
@Get(':teamId/members')
@ApiOperation({ summary: 'Get team members' })
@ApiResponse({ status: 200, description: 'Team members', type: GetTeamMembersOutputDTO })
async getMembers(@Param('teamId') teamId: string): Promise<GetTeamMembersOutputDTO> {
const presenter = await this.teamService.getMembers(teamId);
return presenter.getResponseModel()!;
return await this.teamService.getMembers(teamId);
}
@Get(':teamId/join-requests')
@ApiOperation({ summary: 'Get team join requests' })
@ApiResponse({ status: 200, description: 'Team join requests', type: GetTeamJoinRequestsOutputDTO })
async getJoinRequests(@Param('teamId') teamId: string): Promise<GetTeamJoinRequestsOutputDTO> {
const presenter = await this.teamService.getJoinRequests(teamId);
return presenter.getResponseModel()!;
return await this.teamService.getJoinRequests(teamId);
}
@Post()
@ApiOperation({ summary: 'Create a new team' })
@ApiResponse({ status: 201, description: 'Team created', type: CreateTeamOutputDTO })
async create(@Body() input: CreateTeamInputDTO, @Req() req: Request): Promise<CreateTeamOutputDTO> {
const userId = req['user']?.userId;
const presenter = await this.teamService.create(input, userId);
return presenter.responseModel;
const userId = (req as any)['user']?.userId;
return await this.teamService.create(input, userId);
}
@Patch(':teamId')
@ApiOperation({ summary: 'Update team' })
@ApiResponse({ status: 200, description: 'Team updated', type: UpdateTeamOutputDTO })
async update(@Param('teamId') teamId: string, @Body() input: UpdateTeamInputDTO, @Req() req: Request): Promise<UpdateTeamOutputDTO> {
const userId = req['user']?.userId;
const presenter = await this.teamService.update(teamId, input, userId);
return presenter.responseModel;
async update(@Param('teamId') teamId: string, @Body() input: UpdateTeamInput, @Req() req: Request): Promise<UpdateTeamOutputDTO> {
const userId = (req as any)['user']?.userId;
return await this.teamService.update(teamId, input, userId);
}
@Get('driver/:driverId')
@@ -75,8 +69,7 @@ export class TeamController {
@ApiResponse({ status: 200, description: 'Driver\'s team', type: GetDriverTeamOutputDTO })
@ApiResponse({ status: 404, description: 'Team not found' })
async getDriverTeam(@Param('driverId') driverId: string): Promise<GetDriverTeamOutputDTO | null> {
const presenter = await this.teamService.getDriverTeam(driverId);
return presenter.getResponseModel();
return await this.teamService.getDriverTeam(driverId);
}
@Get(':teamId/members/:driverId')
@@ -84,7 +77,6 @@ export class TeamController {
@ApiResponse({ status: 200, description: 'Team membership', type: GetTeamMembershipOutputDTO })
@ApiResponse({ status: 404, description: 'Membership not found' })
async getMembership(@Param('teamId') teamId: string, @Param('driverId') driverId: string): Promise<GetTeamMembershipOutputDTO | null> {
const presenter = await this.teamService.getMembership(teamId, driverId);
return presenter.responseModel;
return await this.teamService.getMembership(teamId, driverId);
}
}