Skip to content

Commit

Permalink
fix: 🐛 teamInfo 의 lastEventTime 을 잘못 구하던 문제 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jpham005 committed Apr 8, 2024
1 parent 09eaf83 commit 6fb55be
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions app/src/api/team/team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class TeamService {
Pick<team, 'status' | 'users' | 'teamsUploads'> & {
evalLogs: scale_team[];
userPreviews: UserPreview[];
lastEventTime: Date;
}
>();

Expand Down Expand Up @@ -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,
});

Expand All @@ -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,
Expand Down

0 comments on commit 6fb55be

Please sign in to comment.