From 6fb55bec1c5dcc3008a907748cc871ec7a83b15f Mon Sep 17 00:00:00 2001 From: jaham Date: Tue, 9 Apr 2024 01:06:40 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=20teamInfo=20=EC=9D=98=20lastEvent?= =?UTF-8?q?Time=20=EC=9D=84=20=EC=9E=98=EB=AA=BB=20=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EB=8D=98=20=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/api/team/team.service.ts | 37 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/app/src/api/team/team.service.ts b/app/src/api/team/team.service.ts index e0a064db..d90f15a8 100644 --- a/app/src/api/team/team.service.ts +++ b/app/src/api/team/team.service.ts @@ -113,6 +113,7 @@ export class TeamService { Pick & { evalLogs: scale_team[]; userPreviews: UserPreview[]; + lastEventTime: Date; } >(); @@ -156,6 +157,22 @@ export class TeamService { ...conditionalProjectPreview('projectId', 'project'), }, evalLogs: '$scale_teams', + // scale_teams 는 종료된 것만 있음 + lastEventTime: { + $max: [ + '$createdAt', + '$lockedAt', + '$closedAt', + { + $cond: [ + { $eq: ['$status', 'finished'] }, + { $max: '$scaleTeams.filledAt' }, + null, + ], + }, + { $max: '$teamsUploads.createdAt' }, + ], + }, userPreviews: 1, }); @@ -174,25 +191,7 @@ export class TeamService { occurrence: user.occurrence, })), status: convertTeamStauts(teamInfoAggr.status), - lastEventTime: new Date( - Math.max( - teamInfoAggr.createdAt.getTime(), - teamInfoAggr.lockedAt?.getTime() ?? 0, - teamInfoAggr.closedAt?.getTime() ?? 0, - teamInfoAggr.status === 'finished' - ? teamInfoAggr.evalLogs.reduce( - (lastFilled, evalLog) => - Math.max(evalLog.filledAt!.getTime(), lastFilled), - 0, - ) - : 0, - teamInfoAggr.teamsUploads.reduce( - (lastUpload, upload) => - Math.max(lastUpload, upload.createdAt.getTime()), - 0, - ), - ), - ), + lastEventTime: teamInfoAggr.lastEventTime, moulinette: teamInfoAggr.teamsUploads.length ? { id: teamInfoAggr.teamsUploads[0].id,