import { Column, Model, Table, DataType, CreatedAt, UpdatedAt, HasMany } from "sequelize-typescript"; import UserRole from "./userRole.entity"; @Table({ tableName: "users", comment: "用户表", timestamps: true, createdAt: "created_at", updatedAt: "updated_at" }) export default class User extends Model { @Column({ type: DataType.BIGINT, autoIncrement: true, primaryKey: true }) id!: number; @Column({ type: DataType.STRING(50), allowNull: false, unique: true, comment: "用户名" }) username!: string; @Column({ type: DataType.STRING(255), allowNull: false, comment: "加密密码(bcrypt)" }) password!: string; @Column({ type: DataType.STRING(50), field: "nickname", comment: "昵称" }) nickname!: string; @Column({ type: DataType.STRING(100), field: "email", comment: "邮箱" }) email!: string; @Column({ type: DataType.STRING(20), field: "phone", comment: "手机号" }) phone!: string; @Column({ type: DataType.STRING(255), field: "avatar", comment: "头像URL" }) avatar!: string; @Column({ type: DataType.TINYINT, allowNull: false, defaultValue: 1, comment: "状态: 0-禁用 1-启用" }) status!: number; @Column({ type: DataType.DATE, field: "last_login_at", comment: "最后登录时间" }) lastLoginAt!: Date; @Column({ type: DataType.STRING(45), field: "last_login_ip", comment: "最后登录IP(支持IPv6)" }) lastLoginIp!: string; @HasMany(() => UserRole) userRoles!: UserRole[]; @CreatedAt created_at!: Date; @UpdatedAt updated_at!: Date; }