Files
plates-server/src/health-profiles/models/health-history.model.ts

65 lines
1.5 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, 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[];
}