97 lines
2.1 KiB
TypeScript
97 lines
2.1 KiB
TypeScript
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;
|
||
} |