import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn, } from 'typeorm'; import { Article } from './article.entity'; import { ApiProperty } from '@nestjs/swagger'; @Entity() export class CommentEntity { @ApiProperty({ description: '主键id', type: 'int' }) @PrimaryGeneratedColumn() id: number; @ApiProperty({ description: 'key', type: 'string' }) @Column({ unique: true, nullable: true }) key: string; @ApiProperty({ description: 'score', type: 'number' }) @Column('float', { nullable: true }) score: number; @ApiProperty({ description: 'article', type: 'Article' }) @ManyToOne((type) => Article, (Article) => Article.comments) article: Article; @ApiProperty({ description: 'content', type: 'string' }) @Column('longtext', { nullable: true }) content: string; @ApiProperty({ description: '创建时间', type: 'Date' }) @CreateDateColumn({ type: 'timestamp' }) createdTime: Date; @ApiProperty({ description: '修改时间', type: 'Date' }) @UpdateDateColumn({ type: 'timestamp' }) updatedTime: Date; @ApiProperty({ description: 'publishTime', type: 'Date' }) @Column({ nullable: true }) publishTime: Date; @ApiProperty({ description: '父级', type: 'CommentEntity' }) @ManyToOne( (type) => CommentEntity, (commentEntity) => commentEntity.children, { nullable: true }, ) parent: CommentEntity; @ApiProperty({ description: '子级,多个', type: 'CommentEntity[]' }) @OneToMany((type) => CommentEntity, (commentEntity) => commentEntity.parent) children: CommentEntity[]; }