56 lines
933 B
TypeScript
56 lines
933 B
TypeScript
import {
|
|
Table,
|
|
Column,
|
|
Model,
|
|
DataType,
|
|
Length,
|
|
UpdatedAt,
|
|
CreatedAt,
|
|
ForeignKey,
|
|
BelongsTo,
|
|
HasMany
|
|
} from "sequelize-typescript";
|
|
import Thread from "./thread.model";
|
|
|
|
@Table({
|
|
tableName: "sections",
|
|
modelName: "Section"
|
|
})
|
|
export default class Section 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
|
|
})
|
|
declare root_section_id: number | null;
|
|
|
|
@BelongsTo(() => Section)
|
|
declare root_section: Section;
|
|
|
|
@HasMany(() => Section)
|
|
declare inner_sections: Section[];
|
|
|
|
@HasMany(() => Thread)
|
|
declare threads: Thread[];
|
|
}
|