feat(challenges): 新增今日上报值与目标值字段至排行榜接口
This commit is contained in:
@@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user