feat(challenges): 新增今日上报值与目标值字段至排行榜接口

This commit is contained in:
richarjiang
2025-09-29 17:22:10 +08:00
parent 12acbbd166
commit f13953030b
2 changed files with 26 additions and 0 deletions

View File

@@ -164,6 +164,28 @@ export class ChallengesService {
rankingsRawCount: rankingsRaw.length,
});
const today = dayjs().format('YYYY-MM-DD');
const todayReportsMap = new Map<string, number>();
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,
};
});