Files
plates-server/src/mood-checkins/models/mood-checkin.model.ts
richarjiang f26d8e64c6 feat: 新增心情打卡功能模块
实现心情打卡的完整功能,包括数据库表设计、API接口、业务逻辑和文档说明。支持记录多种心情类型、强度评分和统计分析功能。
2025-08-21 15:20:05 +08:00

97 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}