feat(badges): 更新勋章系统,支持UUID作为勋章ID类型

feat(challenges): 优化进度报告,添加睡眠挑战勋章授予逻辑
fix(push-notifications): 修复推送测试服务初始化返回值问题
This commit is contained in:
2025-11-15 23:25:02 +08:00
parent 9c7bcb6083
commit 1c033cd801
4 changed files with 46 additions and 33 deletions

View File

@@ -473,13 +473,22 @@ export class ChallengesService {
} }
} }
this.winstonLogger.info('progress report updated', {
if (report.reportedValue >= reportCompletedValue && !dayjs(participant.lastProgressAt).isSame(dayjs(), 'd')) { context: 'reportProgress',
participant.progressValue++ userId,
participant.lastProgressAt = now; challengeId,
reportDate,
reportedValue,
})
// 🎖️ 检查是否为睡眠挑战且完成了第一次打卡,授予 goodSleep 勋章 // 🎖️ 检查是否为睡眠挑战且完成了第一次打卡,授予 goodSleep 勋章
if (challenge.type === ChallengeType.SLEEP) { if (challenge.type === ChallengeType.SLEEP) {
this.winstonLogger.info('检查是否为睡眠挑战且完成了第一次打卡,授予 goodSleep 勋章', {
context: 'reportProgress',
userId,
challengeId,
badgeCode: 'goodSleep',
})
try { try {
await this.badgeService.awardBadge(userId, 'goodSleep', { await this.badgeService.awardBadge(userId, 'goodSleep', {
source: BadgeSource.CHALLENGE, source: BadgeSource.CHALLENGE,
@@ -505,6 +514,10 @@ export class ChallengesService {
}); });
} }
} }
if (report.reportedValue >= reportCompletedValue && !dayjs(participant.lastProgressAt).isSame(dayjs(), 'd')) {
participant.progressValue++
participant.lastProgressAt = now;
} }
if (participant.progressValue >= (participant.challenge?.minimumCheckInDays || 0) && participant.status !== ChallengeParticipantStatus.COMPLETED) { if (participant.progressValue >= (participant.challenge?.minimumCheckInDays || 0) && participant.status !== ChallengeParticipantStatus.COMPLETED) {

View File

@@ -32,7 +32,7 @@ export class PushTestService implements OnModuleInit {
async onModuleInit() { async onModuleInit() {
// 检查是否启用推送测试 // 检查是否启用推送测试
const enablePushTest = this.configService.get<boolean>('ENABLE_PUSH_TEST', false); const enablePushTest = this.configService.get<boolean>('ENABLE_PUSH_TEST', false);
return
if (!enablePushTest) { if (!enablePushTest) {
this.logger.log('Push test is disabled. Skipping...'); this.logger.log('Push test is disabled. Skipping...');
return; return;

View File

@@ -31,11 +31,11 @@ export enum BadgeSource {
}) })
export class UserBadge extends Model { export class UserBadge extends Model {
@Column({ @Column({
type: DataType.INTEGER, type: DataType.CHAR(36),
defaultValue: DataType.UUIDV4,
primaryKey: true, primaryKey: true,
autoIncrement: true,
}) })
declare id: number; declare id: string;
@ForeignKey(() => User) @ForeignKey(() => User)
@Column({ @Column({

View File

@@ -78,7 +78,7 @@ export class BadgeService {
* @param userId 用户ID * @param userId 用户ID
*/ */
async getUserBadges(userId: string): Promise<Array<{ async getUserBadges(userId: string): Promise<Array<{
id: number; id: string;
code: string; code: string;
name: string; name: string;
description: string; description: string;