Subd/server/models/thread.model.ts

66 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-04-23 12:08:46 +04:00
import {
Table,
Column,
Model,
DataType,
Length,
UpdatedAt,
CreatedAt,
ForeignKey,
BelongsTo,
HasMany
} from "sequelize-typescript";
import Section from "./section.model";
import User from "./user.model";
import Message from "./message.model";
@Table({
tableName: "threads",
modelName: "Thread"
})
export default class Thread extends Model {
@Column({
primaryKey: true,
autoIncrement: true,
type: DataType.INTEGER
})
declare id: number;
@Length({ min: 1 })
@Column({
allowNull: false,
defaultValue: "Unknown",
type: DataType.STRING
})
declare name: string;
@CreatedAt
declare created_at: Date;
@UpdatedAt
declare updated_at: Date;
@ForeignKey(() => Section)
@Column({
type: DataType.INTEGER,
allowNull: false
})
declare section_id: number;
@BelongsTo(() => Section)
declare section: Section;
@ForeignKey(() => User)
@Column({
type: DataType.INTEGER,
allowNull: false
})
declare creator_id: number | null;
@BelongsTo(() => User)
declare creator: User;
@HasMany(() => Message)
declare messages: Message[];
}