Subd/server/models/section.model.ts

56 lines
933 B
TypeScript
Raw Permalink 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 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[];
}