import { Column, Model, Table, DataType, ForeignKey, BelongsTo } from 'sequelize-typescript'; import { FamilyRole } from '../enums/health-profile.enum'; import { User } from '../../users/models/user.model'; import { FamilyGroup } from './family-group.model'; /** * 家庭成员表 */ @Table({ tableName: 't_family_members', underscored: true, indexes: [ { unique: true, fields: ['family_group_id', 'user_id'], }, ], createdAt: false, updatedAt: false, }) export class FamilyMember extends Model { @Column({ type: DataType.STRING(50), primaryKey: true, comment: '成员记录ID', }) declare id: string; @ForeignKey(() => FamilyGroup) @Column({ type: DataType.STRING(50), allowNull: false, comment: '家庭组ID', }) declare familyGroupId: string; @ForeignKey(() => User) @Column({ type: DataType.STRING(50), allowNull: false, comment: '用户ID', }) declare userId: string; @Column({ type: DataType.STRING(20), allowNull: false, defaultValue: FamilyRole.MEMBER, comment: '角色:owner | admin | member', }) declare role: FamilyRole; @Column({ type: DataType.STRING(50), allowNull: true, comment: '关系(如:配偶、父母、子女)', }) declare relationship: string | null; @Column({ type: DataType.BOOLEAN, allowNull: false, defaultValue: true, comment: '是否可查看健康数据', }) declare canViewHealthData: boolean; @Column({ type: DataType.BOOLEAN, allowNull: false, defaultValue: false, comment: '是否可管理健康数据', }) declare canManageHealthData: boolean; @Column({ type: DataType.BOOLEAN, allowNull: false, defaultValue: true, comment: '是否接收异常提醒', }) declare receiveAlerts: boolean; @Column({ type: DataType.DATE, defaultValue: DataType.NOW, comment: '加入时间', }) declare joinedAt: Date; // 关联关系 @BelongsTo(() => FamilyGroup, 'familyGroupId') declare familyGroup: FamilyGroup; @BelongsTo(() => User, 'userId') declare user: User; }