Skip to content

Commit

Permalink
Merge pull request #39 from 5th-Neordinary-HACKATHON-MEETA/issue/38
Browse files Browse the repository at this point in the history
feat: 팀 참가 API 구현
  • Loading branch information
JinhyeokFang authored Nov 25, 2023
2 parents 5a29fbb + 7e38550 commit f8898be
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/common/response/response.code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export const RESPONSE_CODE: Record<number, ResponseCode> = {
message: '존재하지 않는 팀입니다.',
status: HttpStatus.NOT_FOUND,
},
24090: {
code: 24090,
message: '이미 참여한 유저입니다.',
status: HttpStatus.CONFLICT,
},

//MEETING
34040: {
Expand Down
11 changes: 11 additions & 0 deletions src/teams/teams.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,15 @@ export class TeamsController {
teams,
});
}

/* 팀 참가하기 */
@Put('/:teamId/join')
@UseGuards(JwtAuthGuard)
async joinTeam(
@AuthUser() user: User,
@Param('teamId') teamId: string,
): Promise<ResponseBody> {
await this.teamsService.joinTeam(user, teamId);
return SuccessResponse(RESPONSE_CODE[2000], null);
}
}
25 changes: 25 additions & 0 deletions src/teams/teams.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,29 @@ export class TeamsService {
team.endedAt = editTeamDto.endedAt || team.endedAt;
await this.teamRepository.save(team);
}

/* 팀 참여하기 */
async joinTeam(user: User, teamId: string): Promise<void> {
const team = await this.teamRepository.findOne({
where: {
id: teamId,
},
});
if (team === null) {
throw new Exception(RESPONSE_CODE[4040], null);
}
const participant = await this.participantRepository.findOne({
where: {
user: { id: user.id },
team: { id: team.id },
},
});
if (participant !== null) {
throw new Exception(RESPONSE_CODE[24090], null);
}
const newParticipant = new Participant();
newParticipant.team = team;
newParticipant.user = user;
await this.participantRepository.save(newParticipant);
}
}

0 comments on commit f8898be

Please sign in to comment.