Compare commits
2 Commits
89d4a7c78f
...
ee5af33a96
Author | SHA1 | Date | |
---|---|---|---|
ee5af33a96 | |||
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>[];
|
||||
}
|
||||
|
16
src/modules/user/entities/access.token.entity.ts
Normal file
16
src/modules/user/entities/access.token.entity.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { Entity, OneToOne } from 'typeorm';
|
||||
|
||||
import { BaseToken } from '@/modules/user/entities/base.token';
|
||||
import { RefreshTokenEntity } from '@/modules/user/entities/refresh.token.entity';
|
||||
|
||||
/**
|
||||
* 用户认证token模型
|
||||
*/
|
||||
@Entity('user_access_token')
|
||||
export class AccessTokenEntity extends BaseToken {
|
||||
/**
|
||||
* 关联的刷新令牌
|
||||
*/
|
||||
@OneToOne(() => RefreshTokenEntity, (token) => token.accessToken, { cascade: true })
|
||||
refreshToken: string;
|
||||
}
|
24
src/modules/user/entities/base.token.ts
Normal file
24
src/modules/user/entities/base.token.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { BaseEntity, Column, CreateDateColumn, PrimaryColumn } from 'typeorm';
|
||||
|
||||
/**
|
||||
* Token模型
|
||||
*/
|
||||
@Exclude()
|
||||
export abstract class BaseToken extends BaseEntity {
|
||||
@PrimaryColumn({ type: 'varchar', generated: 'uuid', length: 36 })
|
||||
id: string;
|
||||
|
||||
@Column({ length: 500, comment: '令牌字符串' })
|
||||
value: string;
|
||||
|
||||
@Column({
|
||||
comment: '令牌过期时间',
|
||||
})
|
||||
expired_at: Date;
|
||||
|
||||
@CreateDateColumn({
|
||||
comment: '令牌创建时间',
|
||||
})
|
||||
createdAt: Date;
|
||||
}
|
17
src/modules/user/entities/refresh.token.entity.ts
Normal file
17
src/modules/user/entities/refresh.token.entity.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Entity, JoinColumn, OneToOne, Relation } from 'typeorm';
|
||||
|
||||
import { AccessTokenEntity } from '@/modules/user/entities/access.token.entity';
|
||||
import { BaseToken } from '@/modules/user/entities/base.token';
|
||||
|
||||
/**
|
||||
* 刷新Token的Token模型
|
||||
*/
|
||||
@Entity('user_refresh_token')
|
||||
export class RefreshTokenEntity extends BaseToken {
|
||||
/**
|
||||
* 关联的登录令牌
|
||||
*/
|
||||
@OneToOne(() => AccessTokenEntity, (token) => token.refreshToken, { onDelete: 'CASCADE' })
|
||||
@JoinColumn()
|
||||
accessToken: Relation<AccessTokenEntity>;
|
||||
}
|
Loading…
Reference in New Issue
Block a user