You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.1 KiB
75 lines
2.1 KiB
import { Sequelize, DataTypes, Optional, Model } from "sequelize"
|
|
|
|
interface UserInfoAttributes {
|
|
id: number
|
|
user_id: number
|
|
nickname: string
|
|
email: string
|
|
avatar: string
|
|
tel: string
|
|
|
|
createdAt?: Date
|
|
updatedAt?: Date
|
|
deletedAt?: Date
|
|
}
|
|
|
|
export interface UserInfoInput extends Optional<UserInfoAttributes, "id" | "email" | "nickname" | "avatar" | "tel"> {}
|
|
export interface UserInfoOuput extends Required<UserInfoAttributes> {}
|
|
export type TUserInfoModel = ReturnType<typeof UserInfoModel>
|
|
|
|
type DT = typeof DataTypes
|
|
export default function UserInfoModel(sequelize: Sequelize, DataTypes: DT) {
|
|
class UserInfo extends Model<UserInfoAttributes, UserInfoInput> implements UserInfoAttributes {
|
|
public id: number
|
|
public user_id: number
|
|
public nickname: string
|
|
public email: string
|
|
public avatar: string
|
|
public tel: string
|
|
|
|
// timestamps!
|
|
public readonly createdAt!: Date
|
|
public readonly updatedAt!: Date
|
|
public readonly deletedAt!: Date
|
|
}
|
|
UserInfo.init(
|
|
{
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
autoIncrement: true,
|
|
primaryKey: true,
|
|
},
|
|
user_id: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
},
|
|
nickname: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
email: {
|
|
type: DataTypes.STRING,
|
|
},
|
|
avatar: {
|
|
type: DataTypes.STRING,
|
|
},
|
|
tel: {
|
|
type: DataTypes.STRING,
|
|
},
|
|
},
|
|
{
|
|
modelName: "UserInfo",
|
|
sequelize,
|
|
timestamps: true,
|
|
paranoid: true, // 对模型施加了一个软删除
|
|
},
|
|
)
|
|
// 覆盖User的toJSON方法
|
|
interface UserInfo {
|
|
toJSON: () => UserInfoOuput
|
|
}
|
|
UserInfo.associate = function (models) {
|
|
models["UserInfo"].belongsTo(models["User"], { foreignKey: "user_id" })
|
|
}
|
|
return UserInfo
|
|
}
|
|
|