feat: 新增心情打卡功能模块

实现心情打卡的完整功能,包括数据库表设计、API接口、业务逻辑和文档说明。支持记录多种心情类型、强度评分和统计分析功能。
This commit is contained in:
richarjiang
2025-08-21 15:20:05 +08:00
parent 513d6e071d
commit f26d8e64c6
9 changed files with 888 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
import { Column, Model, Table, DataType, ForeignKey, BelongsTo } from 'sequelize-typescript';
import { User } from '../../users/models/user.model';
export enum MoodType {
HAPPY = 'happy', // 开心
EXCITED = 'excited', // 心动
THRILLED = 'thrilled', // 兴奋
CALM = 'calm', // 平静
ANXIOUS = 'anxious', // 焦虑
SAD = 'sad', // 难过
LONELY = 'lonely', // 孤独
WRONGED = 'wronged', // 委屈
ANGRY = 'angry', // 生气
TIRED = 'tired' // 心累
}
@Table({
tableName: 't_mood_checkins',
underscored: true,
})
export class MoodCheckin extends Model {
@Column({
type: DataType.UUID,
defaultValue: DataType.UUIDV4,
primaryKey: true,
})
declare id: string;
@ForeignKey(() => User)
@Column({
type: DataType.STRING,
allowNull: false,
comment: '用户ID',
})
declare userId: string;
@BelongsTo(() => User)
declare user: User;
@Column({
type: DataType.ENUM(...Object.values(MoodType)),
allowNull: false,
comment: '心情类型:喜怒哀乐',
})
declare moodType: MoodType;
@Column({
type: DataType.INTEGER,
allowNull: false,
defaultValue: 5,
comment: '心情强度1-10',
validate: {
min: 1,
max: 10,
},
})
declare intensity: number;
@Column({
type: DataType.TEXT,
allowNull: true,
comment: '心情描述',
})
declare description: string | null;
@Column({
type: DataType.DATEONLY,
allowNull: false,
comment: '打卡日期YYYY-MM-DD',
})
declare checkinDate: string;
@Column({
type: DataType.JSON,
allowNull: true,
comment: '扩展数据(标签、触发事件等)',
})
declare metadata: Record<string, any> | null;
@Column({
type: DataType.DATE,
defaultValue: DataType.NOW,
})
declare createdAt: Date;
@Column({
type: DataType.DATE,
defaultValue: DataType.NOW,
})
declare updatedAt: Date;
@Column({
type: DataType.BOOLEAN,
defaultValue: false,
})
declare deleted: boolean;
}