diff --git a/src/challenges/challenges.service.ts b/src/challenges/challenges.service.ts index 66475c2..122e133 100644 --- a/src/challenges/challenges.service.ts +++ b/src/challenges/challenges.service.ts @@ -164,6 +164,28 @@ export class ChallengesService { rankingsRawCount: rankingsRaw.length, }); + const today = dayjs().format('YYYY-MM-DD'); + + const todayReportsMap = new Map(); + + if (rankingsRaw.length) { + const rankingUserIds = rankingsRaw.map((item) => item.userId); + + const reports = await this.progressReportModel.findAll({ + where: { + challengeId, + reportDate: today, + userId: { + [Op.in]: rankingUserIds, + }, + }, + }); + + for (const report of reports) { + todayReportsMap.set(report.userId, report.reportedValue ?? 0); + } + } + const completionTarget = challenge.minimumCheckInDays const progress = participation @@ -178,6 +200,8 @@ export class ChallengesService { avatar: item.user?.avatar ?? null, metric: `${item.progressValue}/${itemTarget}天`, badge: this.resolveRankingBadge(index), + todayReportedValue: todayReportsMap.get(item.userId) ?? 0, + todayTargetValue: challenge.targetValue, }; }); diff --git a/src/challenges/dto/challenge-progress.dto.ts b/src/challenges/dto/challenge-progress.dto.ts index 8a5eac1..70b64ea 100644 --- a/src/challenges/dto/challenge-progress.dto.ts +++ b/src/challenges/dto/challenge-progress.dto.ts @@ -11,4 +11,6 @@ export interface RankingItemDto { avatar: string | null; metric: string; badge?: string; + todayReportedValue: number; + todayTargetValue: number; }