feat(challenges): 新增今日上报值与目标值字段至排行榜接口
This commit is contained in:
@@ -164,6 +164,28 @@ export class ChallengesService {
|
|||||||
rankingsRawCount: rankingsRaw.length,
|
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 completionTarget = challenge.minimumCheckInDays
|
||||||
|
|
||||||
const progress = participation
|
const progress = participation
|
||||||
@@ -178,6 +200,8 @@ export class ChallengesService {
|
|||||||
avatar: item.user?.avatar ?? null,
|
avatar: item.user?.avatar ?? null,
|
||||||
metric: `${item.progressValue}/${itemTarget}天`,
|
metric: `${item.progressValue}/${itemTarget}天`,
|
||||||
badge: this.resolveRankingBadge(index),
|
badge: this.resolveRankingBadge(index),
|
||||||
|
todayReportedValue: todayReportsMap.get(item.userId) ?? 0,
|
||||||
|
todayTargetValue: challenge.targetValue,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ export interface RankingItemDto {
|
|||||||
avatar: string | null;
|
avatar: string | null;
|
||||||
metric: string;
|
metric: string;
|
||||||
badge?: string;
|
badge?: string;
|
||||||
|
todayReportedValue: number;
|
||||||
|
todayTargetValue: number;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user