import { Column, Model, Table, DataType, HasMany, ForeignKey, BelongsTo } from 'sequelize-typescript'; import { HealthHistoryCategory } from '../enums/health-profile.enum'; import { User } from '../../users/models/user.model'; import { HealthHistoryItem } from './health-history-item.model'; /** * 健康史主表 * 记录用户各分类的健康史状态 */ @Table({ tableName: 't_health_histories', underscored: true, }) export class HealthHistory extends Model { @Column({ type: DataType.STRING(50), primaryKey: true, comment: '健康史记录ID', }) declare id: string; @ForeignKey(() => User) @Column({ type: DataType.STRING(50), allowNull: false, comment: '用户ID', }) declare userId: string; @Column({ type: DataType.STRING(50), allowNull: false, comment: '健康史分类:allergy | disease | surgery | familyDisease', }) declare category: HealthHistoryCategory; @Column({ type: DataType.BOOLEAN, allowNull: true, comment: '是否有该类健康史:null=未回答, true=有, false=无', }) declare hasHistory: boolean | null; @Column({ type: DataType.DATE, defaultValue: DataType.NOW, comment: '创建时间', }) declare createdAt: Date; @Column({ type: DataType.DATE, defaultValue: DataType.NOW, comment: '更新时间', }) declare updatedAt: Date; // 关联关系 @BelongsTo(() => User, 'userId') declare user: User; @HasMany(() => HealthHistoryItem, 'healthHistoryId') declare items: HealthHistoryItem[]; }