resolve manual DTOs
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
import { Controller, Get, Post, Patch, Body, Param } from '@nestjs/common';
|
||||
import { ApiTags, ApiResponse, ApiOperation, ApiBody } from '@nestjs/swagger';
|
||||
import { Controller, Get, Post, Patch, Body, Req, Param } from '@nestjs/common';
|
||||
import { Request } from 'express';
|
||||
import { ApiTags, ApiResponse, ApiOperation } from '@nestjs/swagger';
|
||||
import { TeamService } from './TeamService';
|
||||
import { AllTeamsViewModel, DriverTeamViewModel, TeamDetailsViewModel, TeamMembersViewModel, TeamJoinRequestsViewModel, CreateTeamInput, CreateTeamOutput, UpdateTeamInput, UpdateTeamOutput, ApproveTeamJoinRequestInput, ApproveTeamJoinRequestOutput, RejectTeamJoinRequestInput, RejectTeamJoinRequestOutput } from './dto/TeamDto';
|
||||
import { GetAllTeamsOutputDTO } from './dtos/GetAllTeamsOutputDTO';
|
||||
import { GetTeamDetailsOutputDTO } from './dtos/GetTeamDetailsOutputDTO';
|
||||
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 { UpdateTeamOutputDTO } from './dtos/UpdateTeamOutputDTO';
|
||||
import { GetDriverTeamOutputDTO } from './dtos/GetDriverTeamOutputDTO';
|
||||
import { GetTeamMembershipOutputDTO } from './dtos/GetTeamMembershipOutputDTO';
|
||||
|
||||
@ApiTags('teams')
|
||||
@Controller('teams')
|
||||
@@ -10,91 +20,63 @@ export class TeamController {
|
||||
|
||||
@Get('all')
|
||||
@ApiOperation({ summary: 'Get all teams' })
|
||||
@ApiResponse({ status: 200, description: 'List of all teams', type: AllTeamsViewModel })
|
||||
async getAllTeams(): Promise<AllTeamsViewModel> {
|
||||
return this.teamService.getAllTeams();
|
||||
@ApiResponse({ status: 200, description: 'List of all teams', type: GetAllTeamsOutputDTO })
|
||||
async getAll(): Promise<GetAllTeamsOutputDTO> {
|
||||
return this.teamService.getAll();
|
||||
}
|
||||
|
||||
@Get(':teamId')
|
||||
@ApiOperation({ summary: 'Get team details' })
|
||||
@ApiResponse({ status: 200, description: 'Team details', type: TeamDetailsViewModel })
|
||||
@ApiResponse({ status: 200, description: 'Team details', type: GetTeamDetailsOutputDTO })
|
||||
@ApiResponse({ status: 404, description: 'Team not found' })
|
||||
async getTeamDetails(
|
||||
@Param('teamId') teamId: string,
|
||||
): Promise<TeamDetailsViewModel | null> {
|
||||
return this.teamService.getTeamDetails(teamId);
|
||||
async getDetails(@Param('teamId') teamId: string, @Req() req: Request): Promise<GetTeamDetailsOutputDTO | null> {
|
||||
const userId = req['user']?.userId;
|
||||
return this.teamService.getDetails(teamId, userId);
|
||||
}
|
||||
|
||||
@Get(':teamId/members')
|
||||
@ApiOperation({ summary: 'Get team members' })
|
||||
@ApiResponse({ status: 200, description: 'Team members', type: TeamMembersViewModel })
|
||||
async getTeamMembers(@Param('teamId') teamId: string): Promise<TeamMembersViewModel> {
|
||||
return this.teamService.getTeamMembers(teamId);
|
||||
@ApiResponse({ status: 200, description: 'Team members', type: GetTeamMembersOutputDTO })
|
||||
async getMembers(@Param('teamId') teamId: string): Promise<GetTeamMembersOutputDTO> {
|
||||
return this.teamService.getMembers(teamId);
|
||||
}
|
||||
|
||||
@Get(':teamId/join-requests')
|
||||
@ApiOperation({ summary: 'Get team join requests' })
|
||||
@ApiResponse({ status: 200, description: 'Team join requests', type: TeamJoinRequestsViewModel })
|
||||
async getTeamJoinRequests(@Param('teamId') teamId: string): Promise<TeamJoinRequestsViewModel> {
|
||||
return this.teamService.getTeamJoinRequests(teamId);
|
||||
}
|
||||
|
||||
@Post(':teamId/join-requests/approve')
|
||||
@ApiOperation({ summary: 'Approve a team join request' })
|
||||
@ApiBody({ type: ApproveTeamJoinRequestInput })
|
||||
@ApiResponse({ status: 200, description: 'Join request approved', type: ApproveTeamJoinRequestOutput })
|
||||
@ApiResponse({ status: 404, description: 'Join request not found' })
|
||||
async approveJoinRequest(
|
||||
@Param('teamId') teamId: string,
|
||||
@Body() input: ApproveTeamJoinRequestInput,
|
||||
): Promise<ApproveTeamJoinRequestOutput> {
|
||||
return this.teamService.approveTeamJoinRequest({ ...input, teamId });
|
||||
}
|
||||
|
||||
@Post(':teamId/join-requests/reject')
|
||||
@ApiOperation({ summary: 'Reject a team join request' })
|
||||
@ApiBody({ type: RejectTeamJoinRequestInput })
|
||||
@ApiResponse({ status: 200, description: 'Join request rejected', type: RejectTeamJoinRequestOutput })
|
||||
@ApiResponse({ status: 404, description: 'Join request not found' })
|
||||
async rejectJoinRequest(
|
||||
@Param('teamId') teamId: string,
|
||||
@Body() input: RejectTeamJoinRequestInput,
|
||||
): Promise<RejectTeamJoinRequestOutput> {
|
||||
return this.teamService.rejectTeamJoinRequest({ ...input, teamId });
|
||||
@ApiResponse({ status: 200, description: 'Team join requests', type: GetTeamJoinRequestsOutputDTO })
|
||||
async getJoinRequests(@Param('teamId') teamId: string): Promise<GetTeamJoinRequestsOutputDTO> {
|
||||
return this.teamService.getJoinRequests(teamId);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create a new team' })
|
||||
@ApiBody({ type: CreateTeamInput })
|
||||
@ApiResponse({ status: 201, description: 'Team created successfully', type: CreateTeamOutput })
|
||||
async createTeam(@Body() input: CreateTeamInput): Promise<CreateTeamOutput> {
|
||||
return this.teamService.createTeam(input);
|
||||
@ApiResponse({ status: 201, description: 'Team created', type: CreateTeamOutputDTO })
|
||||
async create(@Body() input: CreateTeamInputDTO, @Req() req: Request): Promise<CreateTeamOutputDTO> {
|
||||
const userId = req['user']?.userId;
|
||||
return this.teamService.create(input, userId);
|
||||
}
|
||||
|
||||
@Patch(':teamId')
|
||||
@ApiOperation({ summary: 'Update team details' })
|
||||
@ApiBody({ type: UpdateTeamInput })
|
||||
@ApiResponse({ status: 200, description: 'Team updated successfully', type: UpdateTeamOutput })
|
||||
@ApiResponse({ status: 404, description: 'Team not found' })
|
||||
async updateTeam(
|
||||
@Param('teamId') teamId: string,
|
||||
@Body() input: UpdateTeamInput,
|
||||
): Promise<UpdateTeamOutput> {
|
||||
return this.teamService.updateTeam({ ...input, 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;
|
||||
return this.teamService.update(teamId, input, userId);
|
||||
}
|
||||
|
||||
@Get('driver/:driverId')
|
||||
@ApiOperation({ summary: 'Get team for a driver' })
|
||||
@ApiResponse({ status: 200, description: 'Driver team membership', type: DriverTeamViewModel })
|
||||
@ApiResponse({ status: 404, description: 'Driver not in a team' })
|
||||
async getDriverTeam(@Param('driverId') driverId: string): Promise<DriverTeamViewModel | null> {
|
||||
return this.teamService.getDriverTeam({ teamId: '', driverId });
|
||||
@ApiOperation({ summary: 'Get driver\'s team' })
|
||||
@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> {
|
||||
return this.teamService.getDriverTeam(driverId);
|
||||
}
|
||||
|
||||
@Get('leaderboard')
|
||||
@ApiOperation({ summary: 'Get teams leaderboard' })
|
||||
@ApiResponse({ status: 200, description: 'Teams leaderboard' })
|
||||
async getTeamsLeaderboard(): Promise<any> {
|
||||
return this.teamService.getTeamsLeaderboard();
|
||||
@Get(':teamId/members/:driverId')
|
||||
@ApiOperation({ summary: 'Get team membership for a driver' })
|
||||
@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> {
|
||||
return this.teamService.getMembership(teamId, driverId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user