From 3242623d094bae731a9d2732a3457f8edffb1561 Mon Sep 17 00:00:00 2001 From: rladydgn <39542757+rladydgn@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:03:55 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=8C=80=ED=9A=8C=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=EC=9D=84=20=EC=A7=84=ED=96=89=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?sort?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/competition.service.ts | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/be/algo-with-me-api/src/competition/services/competition.service.ts b/be/algo-with-me-api/src/competition/services/competition.service.ts index dfc58ea..b71a69b 100644 --- a/be/algo-with-me-api/src/competition/services/competition.service.ts +++ b/be/algo-with-me-api/src/competition/services/competition.service.ts @@ -61,8 +61,13 @@ export class CompetitionService { ) {} async findAll() { - const competitionList = await this.competitionRepository.find(); - const competitionSimpleResponseDtos: CompetitionSimpleResponseDto[] = []; + const competitionList = await this.competitionRepository.find({ + order: { + startsAt: 'DESC', + }, + }); + const competitionSimpleProgressResponseDtos: CompetitionSimpleResponseDto[] = []; + const competitionSimpleNotProgressResponseDtos: CompetitionSimpleResponseDto[] = []; for (const competition of competitionList) { // 대회별 참가자 rows를 조회해야 함. 응답 속도가 늦어진다면 참가자 수를 저장하는 column 추가 필요 const joinedUsers: CompetitionParticipant[] = @@ -71,11 +76,27 @@ export class CompetitionService { competitionId: competition.id, }, }); - competitionSimpleResponseDtos.push( - CompetitionSimpleResponseDto.from(competition, joinedUsers.length), - ); + if (this.isInProgress(competition)) { + competitionSimpleProgressResponseDtos.push( + CompetitionSimpleResponseDto.from(competition, joinedUsers.length), + ); + } else { + competitionSimpleNotProgressResponseDtos.push( + CompetitionSimpleResponseDto.from(competition, joinedUsers.length), + ); + } } - return competitionSimpleResponseDtos; + return competitionSimpleProgressResponseDtos.concat(competitionSimpleNotProgressResponseDtos); + } + + isInProgress(competition: Competition) { + const now: Date = new Date(); + if ( + now.getTime() - competition.startsAt.getTime() > 0 && + competition.endsAt.getTime() - now.getTime() > 0 + ) + return true; + return false; } async findOne(competitionId: number) {