import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, ManyToMany, JoinTable, OneToMany, CreateDateColumn, UpdateDateColumn, } from 'typeorm'; import { Accessory } from './accessory.entity'; import { Category } from './category.entity'; import { Topic } from './topic.entity'; import { CommentEntity } from './comment.entity'; import { ApiProperty } from '@nestjs/swagger'; @Entity() export class Article { @ApiProperty({ description: '文章ID', type: 'number' }) @PrimaryGeneratedColumn() id: number; @ApiProperty({ description: '文章关键key,可以为空,但不能重复', nullable: true, type: 'string', }) @Column({ unique: true, nullable: true }) key: string; @ApiProperty({ description: '文章分数值', nullable: true, type: 'string' }) @Column('float', { nullable: true }) score: number; @ApiProperty({ description: '文章标题', type: 'string' }) @Column() title: string; @ApiProperty({ description: '简介', nullable: true, type: 'string' }) @Column('longtext', { nullable: true }) brief: string; @ApiProperty({ description: '文章内容非html格式', nullable: true, type: 'string', }) @Column('longtext', { nullable: true }) content: string; @ApiProperty({ description: '文章内容html格式', nullable: true, type: 'string', }) @Column('longtext', { nullable: true, name: 'content_html' }) contentHtml: string; @ApiProperty({ description: '基本信息 JSON字符串格式', nullable: true, type: 'string', }) @Column('longtext', { nullable: true }) baseInfo: string; @ApiProperty({ description: '类型', type: 'string', nullable: true }) @Column({ nullable: true }) type: string; @ApiProperty({ description: 'url地址', type: 'string', nullable: true }) @Column({ nullable: true }) url: string; @ApiProperty({ description: '状态', nullable: true, type: 'number' }) @Column({ nullable: true }) status: number; @ApiProperty({ description: '创建时间,更新时候不用处理,系统自动更新', nullable: true, type: 'Date', }) @CreateDateColumn({ type: 'timestamp' }) createdTime: Date; @ApiProperty({ description: '更新时间,更新时候不用处理,系统自动更新', nullable: true, type: 'Date', }) @UpdateDateColumn({ type: 'timestamp' }) updatedTime: Date; @ApiProperty({ description: '发布时间', nullable: true, type: 'Date' }) @Column({ nullable: true }) publishTime: Date; @ApiProperty({ description: '首页图', nullable: true, type: 'Accessory' }) @OneToOne((type) => Accessory, { eager: true }) @JoinColumn() avatar: Accessory; // @ManyToMany(type => Category,{eager:true}) // @JoinTable() @ApiProperty({ description: '类别', nullable: true, type: 'Category[]' }) @ManyToMany((type) => Category, { cascade: true }) @JoinTable({ name: 'article_categories_category', joinColumn: { name: 'articleId', referencedColumnName: 'id' }, inverseJoinColumn: { name: 'categoryId', referencedColumnName: 'id' }, }) categories: Category[]; @ApiProperty({ description: '主题', nullable: true, type: 'Topic[]' }) @ManyToMany((type) => Topic, { cascade: true }) @JoinTable({ name: 'article_topics_topic', joinColumn: { name: 'articleId', referencedColumnName: 'id' }, inverseJoinColumn: { name: 'topicId', referencedColumnName: 'id' }, }) topics: Topic[]; @ApiProperty({ description: '评论', nullable: true, type: 'CommentEntity[]' }) @OneToMany((type) => CommentEntity, (commentEntity) => commentEntity.article) comments: CommentEntity[]; }