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