From 8a71ae03c8cc9be566fa95b36e06ce5a0e5fef90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=AA=E1=86=BC=E1=84=92?= =?UTF-8?q?=E1=85=AE=E1=86=AB?= Date: Fri, 24 Nov 2023 20:44:22 +0900 Subject: [PATCH] =?UTF-8?q?[BE]=20Feat=20:=20=EA=B0=81=20Entity=20?= =?UTF-8?q?=EC=97=90=20softDelete=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/entities/blockPost.entity.ts | 12 +++++++++++- BE/src/entities/blockUser.entity.ts | 13 ++++++++++++- BE/src/entities/post.entity.ts | 4 ++++ BE/src/entities/postImage.entity.ts | 4 ++++ BE/src/entities/user.entity.ts | 4 ++++ BE/src/post/post.service.ts | 4 +++- 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/BE/src/entities/blockPost.entity.ts b/BE/src/entities/blockPost.entity.ts index 9f46483..d156c38 100644 --- a/BE/src/entities/blockPost.entity.ts +++ b/BE/src/entities/blockPost.entity.ts @@ -1,4 +1,11 @@ -import { Entity, Column, ManyToOne, JoinColumn, PrimaryColumn } from 'typeorm'; +import { + Entity, + Column, + ManyToOne, + JoinColumn, + PrimaryColumn, + DeleteDateColumn, +} from 'typeorm'; import { UserEntity } from './user.entity'; import { PostEntity } from './post.entity'; @@ -13,6 +20,9 @@ export class BlockPostEntity { @Column({ nullable: false, default: true }) status: boolean; + @DeleteDateColumn() + delete_date: Date; + @ManyToOne(() => UserEntity, (blocker) => blocker.user_hash) @JoinColumn({ name: 'blocker', referencedColumnName: 'user_hash' }) blockerUser: UserEntity; diff --git a/BE/src/entities/blockUser.entity.ts b/BE/src/entities/blockUser.entity.ts index f3ecb3d..ea1ac0e 100644 --- a/BE/src/entities/blockUser.entity.ts +++ b/BE/src/entities/blockUser.entity.ts @@ -1,5 +1,13 @@ -import { Entity, Column, ManyToOne, JoinColumn, PrimaryColumn } from 'typeorm'; +import { + Entity, + Column, + ManyToOne, + JoinColumn, + PrimaryColumn, + DeleteDateColumn, +} from 'typeorm'; import { UserEntity } from './user.entity'; +import { Delete } from '@nestjs/common'; @Entity('block_user') export class BlockUserEntity { @@ -12,6 +20,9 @@ export class BlockUserEntity { @Column({ nullable: false, default: true }) status: boolean; + @DeleteDateColumn() + delete_date: Date; + @ManyToOne(() => UserEntity, (blocker) => blocker.user_hash) @JoinColumn({ name: 'blocker' }) blockerUser: UserEntity; diff --git a/BE/src/entities/post.entity.ts b/BE/src/entities/post.entity.ts index 4d7389e..a935736 100644 --- a/BE/src/entities/post.entity.ts +++ b/BE/src/entities/post.entity.ts @@ -7,6 +7,7 @@ import { ManyToOne, JoinColumn, OneToMany, + DeleteDateColumn, } from 'typeorm'; import { UserEntity } from './user.entity'; import { PostImageEntity } from './postImage.entity'; @@ -57,6 +58,9 @@ export class PostEntity { }) update_date: Date; + @DeleteDateColumn() + delete_date: Date; + @Column({ length: 2048, nullable: true, charset: 'utf8' }) thumbnail: string; diff --git a/BE/src/entities/postImage.entity.ts b/BE/src/entities/postImage.entity.ts index e0ea1fb..89a6cd8 100644 --- a/BE/src/entities/postImage.entity.ts +++ b/BE/src/entities/postImage.entity.ts @@ -4,6 +4,7 @@ import { Column, ManyToOne, JoinColumn, + DeleteDateColumn, } from 'typeorm'; import { PostEntity } from './post.entity'; @@ -18,6 +19,9 @@ export class PostImageEntity { @Column({ nullable: false }) post_id: number; + @DeleteDateColumn() + delete_date: Date; + @ManyToOne(() => PostEntity, (post) => post.id) @JoinColumn({ name: 'post_id' }) post: PostEntity; diff --git a/BE/src/entities/user.entity.ts b/BE/src/entities/user.entity.ts index 1ebdc57..b7a9ec2 100644 --- a/BE/src/entities/user.entity.ts +++ b/BE/src/entities/user.entity.ts @@ -1,6 +1,7 @@ import { Column, CreateDateColumn, + DeleteDateColumn, Entity, OneToMany, PrimaryGeneratedColumn, @@ -56,4 +57,7 @@ export class UserEntity { @Column({ length: 45, nullable: false, charset: 'utf8', unique: true }) user_hash: string; + + @DeleteDateColumn() + delete_date: Date; } diff --git a/BE/src/post/post.service.ts b/BE/src/post/post.service.ts index 2b03590..85b6af6 100644 --- a/BE/src/post/post.service.ts +++ b/BE/src/post/post.service.ts @@ -105,6 +105,8 @@ export class PostService { where: { id: postId }, relations: ['post_images', 'user'], }); + + console.log(post); if (post === null) { throw new HttpException('없는 게시물입니다.', 400); } @@ -232,7 +234,7 @@ export class PostService { if (!isDataExists) { return false; } else { - await this.postRepository.update({ id: postId }, { status: false }); + await this.postRepository.softDelete({ id: postId }); return true; } }