add user module
This commit is contained in:
parent
89d4a7c78f
commit
1f8d4dc413
@ -1,4 +1,5 @@
|
||||
import { Exclude, Expose, Type } from 'class-transformer';
|
||||
import type { Relation } from 'typeorm';
|
||||
import {
|
||||
BaseEntity,
|
||||
Column,
|
||||
@ -11,9 +12,8 @@ import {
|
||||
TreeParent,
|
||||
} from 'typeorm';
|
||||
|
||||
import type { Relation } from 'typeorm';
|
||||
|
||||
import { PostEntity } from '@/modules/content/entities/post.entity';
|
||||
import { UserEntity } from '@/modules/user/entities/UserEntity';
|
||||
|
||||
@Exclude()
|
||||
@Entity('content_comment')
|
||||
@ -50,4 +50,11 @@ export class CommentEntity extends BaseEntity {
|
||||
@Expose({ groups: ['comment-tree'] })
|
||||
@TreeChildren({ cascade: true })
|
||||
children: Relation<CommentEntity>[];
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.comments, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
author: Relation<UserEntity>;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Exclude, Expose, Type } from 'class-transformer';
|
||||
import type { Relation } from 'typeorm';
|
||||
import {
|
||||
BaseEntity,
|
||||
Column,
|
||||
@ -13,12 +14,11 @@ import {
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import type { Relation } from 'typeorm';
|
||||
|
||||
import { PostBodyType } from '@/modules/content/constants';
|
||||
import { CategoryEntity } from '@/modules/content/entities/category.entity';
|
||||
import { CommentEntity } from '@/modules/content/entities/comment.entity';
|
||||
import { TagEntity } from '@/modules/content/entities/tag.entity';
|
||||
import { UserEntity } from '@/modules/user/entities/UserEntity';
|
||||
|
||||
@Exclude()
|
||||
@Entity('content_posts')
|
||||
@ -89,4 +89,11 @@ export class PostEntity extends BaseEntity {
|
||||
|
||||
@OneToMany(() => CommentEntity, (comment) => comment.post, { cascade: true })
|
||||
comments: Relation<CommentEntity>[];
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.posts, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
author: Relation<UserEntity>;
|
||||
}
|
||||
|
@ -4,10 +4,14 @@ import {
|
||||
CreateDateColumn,
|
||||
DeleteDateColumn,
|
||||
Entity,
|
||||
OneToMany,
|
||||
PrimaryColumn,
|
||||
Relation,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import { CommentEntity, PostEntity } from '@/modules/content/entities';
|
||||
|
||||
/**
|
||||
* 用户实体
|
||||
*/
|
||||
@ -78,4 +82,16 @@ export class UserEntity {
|
||||
@Type(() => Date)
|
||||
@DeleteDateColumn({ comment: '用户销户时间' })
|
||||
deletedAt?: Date;
|
||||
|
||||
/**
|
||||
* 用户发表文章
|
||||
*/
|
||||
@OneToMany(() => PostEntity, (post) => post.author, { cascade: true })
|
||||
posts: Relation<PostEntity>[];
|
||||
|
||||
/**
|
||||
* 用户发表评论
|
||||
*/
|
||||
@OneToMany(() => CommentEntity, (comment) => comment.author, { cascade: true })
|
||||
comments: Relation<CommentEntity>[];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user