feat(challenges): 新增挑战类型字段并重构进度上报逻辑

- 数据库新增 type 列区分 water/exercise/diet/mood/sleep/weight 六类挑战
- 进度上报由增量模式改为绝对值模式,字段 increment_value → reportedValue
- 服务层按 challenge.targetValue 判断当日是否完成,再按 minimumCheckInDays 统计总进度
- 相关 DTO 与模型同步更新,支持新类型返回

BREAKING CHANGE: 上报接口字段由 increment 改为 value,且为当日绝对值
This commit is contained in:
richarjiang
2025-09-29 15:14:48 +08:00
parent d87fc84575
commit 64460a9d68
7 changed files with 103 additions and 59 deletions

View File

@@ -1,5 +1,6 @@
import { Table, Column, DataType, Model, HasMany } from 'sequelize-typescript';
import { ChallengeParticipant } from './challenge-participant.model';
import { col } from 'sequelize';
export enum ChallengeStatus {
UPCOMING = 'upcoming',
@@ -7,6 +8,15 @@ export enum ChallengeStatus {
EXPIRED = 'expired',
}
export enum ChallengeType {
WATER = 'water',
EXERCISE = 'exercise',
DIET = 'diet',
MOOD = 'mood',
SLEEP = 'sleep',
WEIGHT = 'weight',
}
@Table({
tableName: 't_challenges',
underscored: true,
@@ -126,6 +136,14 @@ export class Challenge extends Model {
})
declare ctaLabel: string;
@Column({
type: DataType.ENUM('water', 'exercise', 'diet', 'mood', 'sleep', 'weight'),
allowNull: false,
defaultValue: ChallengeType.WATER,
comment: '挑战类型',
})
declare type: ChallengeType;
@HasMany(() => ChallengeParticipant)
declare participants?: ChallengeParticipant[];
}