import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn, OneToMany, } from 'typeorm'; import { User } from './user.entity'; import { Course } from './course.entity'; @Entity('comments') export class Comment { @PrimaryGeneratedColumn() id: number; @Column({ name: 'course_id' }) courseId: number; @Column({ name: 'user_id' }) userId: number; @Column({ name: 'parent_id', nullable: true }) parentId: number; @Column({ name: 'reply_to_comment_id', nullable: true }) replyToCommentId: number; @Column({ type: 'text' }) content: string; @CreateDateColumn({ name: 'created_at' }) createdAt: Date; @UpdateDateColumn({ name: 'updated_at' }) updatedAt: Date; @ManyToOne(() => User, (user) => user.comments) @JoinColumn({ name: 'user_id' }) user: User; @ManyToOne(() => Course, (course) => course.comments) @JoinColumn({ name: 'course_id' }) course: Course; @ManyToOne(() => Comment, (comment) => comment.replies) @JoinColumn({ name: 'parent_id' }) parent: Comment; @ManyToOne(() => Comment) @JoinColumn({ name: 'reply_to_comment_id' }) replyToComment: Comment; @OneToMany(() => Comment, (comment) => comment.parent) replies: Comment[]; }