Subd/server/models/user.model.ts
2024-04-23 12:08:46 +04:00

82 lines
1.3 KiB
TypeScript

import {
Table,
Column,
Model,
DataType,
IsEmail,
CreatedAt,
UpdatedAt,
ForeignKey,
BelongsTo,
HasMany,
} from "sequelize-typescript";
import Role from "./role.model";
import Thread from "./thread.model";
import Message from "./message.model";
@Table({
timestamps: true,
tableName: "users",
modelName: "user"
})
export default class User extends Model {
@Column({
primaryKey: true,
autoIncrement: true,
type: DataType.INTEGER
})
declare id: number;
@Column({
allowNull: false,
unique: true,
defaultValue: "Unknown",
type: DataType.STRING
})
declare nickname: string;
@Column({
defaultValue: "Unknown",
type: DataType.STRING
})
declare avatar: string;
@IsEmail
@Column({
allowNull: false,
unique: true,
defaultValue: "Unknown",
type: DataType.STRING
})
declare email: string;
@Column({
allowNull: false,
defaultValue: "Unknown",
type: DataType.STRING
})
declare password: string;
@CreatedAt
declare created_at: Date;
@UpdatedAt
declare updated_at: Date;
@ForeignKey(() => Role)
@Column({
allowNull: false,
type: DataType.INTEGER
})
declare role_id: number;
@BelongsTo(() => Role)
declare role: Role;
@HasMany(() => Thread)
declare threads: Thread[];
@HasMany(() => Message)
declare messages: Message[];
}