From 2d1d719d6804a4935f8c54302c4968dba4379f28 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 25 Nov 2023 00:01:32 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[BE]=20Feat=20:=20=EC=97=86=EB=8A=94=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EB=AC=BC=20404=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/post/post.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BE/src/post/post.service.ts b/BE/src/post/post.service.ts index 85b6af6..be0e88f 100644 --- a/BE/src/post/post.service.ts +++ b/BE/src/post/post.service.ts @@ -108,7 +108,7 @@ export class PostService { console.log(post); if (post === null) { - throw new HttpException('없는 게시물입니다.', 400); + throw new HttpException('없는 게시물입니다.', 404); } if (await this.isFiltered(post, userId)) { throw new HttpException('차단한 게시물입니다.', 400); From 44b0a19392e748bca5d873b714e5e348188906c5 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 25 Nov 2023 00:40:59 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[BE]=20Feat=20:=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=B0=A8=EB=8B=A8=ED=95=B4=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/users-block/users-block.controller.ts | 10 ++-- BE/src/users-block/users-block.service.ts | 59 ++++++++++++-------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/BE/src/users-block/users-block.controller.ts b/BE/src/users-block/users-block.controller.ts index c63e6db..8a7cb26 100644 --- a/BE/src/users-block/users-block.controller.ts +++ b/BE/src/users-block/users-block.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Body, Param, Delete } from '@nestjs/common'; +import { Controller, Get, Post, Param, Delete } from '@nestjs/common'; import { UsersBlockService } from './users-block.service'; @Controller('users/block') @@ -13,11 +13,13 @@ export class UsersBlockController { @Post('/:id') async blockUserAdd(@Param('id') id: string) { - await this.usersBlockService.addBlockUser(id); + const userId = 'qwe'; + await this.usersBlockService.addBlockUser(id, userId); } @Delete(':id') - remove(@Param('id') id: string) { - return this.usersBlockService.remove(+id); + async blockUserRemove(@Param('id') id: string) { + const userId = 'qwe'; + await this.usersBlockService.removeBlockUser(id, userId); } } diff --git a/BE/src/users-block/users-block.service.ts b/BE/src/users-block/users-block.service.ts index ee314ce..a375ed1 100644 --- a/BE/src/users-block/users-block.service.ts +++ b/BE/src/users-block/users-block.service.ts @@ -1,8 +1,7 @@ -import { Injectable } from '@nestjs/common'; +import { HttpException, Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { BlockUserEntity } from 'src/entities/blockUser.entity'; import { Repository } from 'typeorm'; -import { HttpException } from '@nestjs/common'; import { UserEntity } from 'src/entities/user.entity'; @Injectable() @@ -14,35 +13,42 @@ export class UsersBlockService { private userRepository: Repository, ) {} - async addBlockUser(id: string) { + async addBlockUser(id: string, userId: string) { const isExistUser = await this.userRepository.findOne({ where: { user_hash: id }, }); if (!isExistUser) { - throw new HttpException('존재하지 않는 유저입니다', 400); + throw new HttpException('존재하지 않는 유저입니다', 404); } const isBlockedUser = await this.blockUserRepository.findOne({ - where: { blocked_user: id, blocker: 'qwe', status: true }, + where: { blocked_user: id, blocker: userId }, + withDeleted: true, }); - - console.log(isBlockedUser); - if (isBlockedUser) { - throw new HttpException('이미 차단된 유저입니다', 400); - } - - const blockUserEntity = new BlockUserEntity(); - blockUserEntity.blocker = 'qwe'; - blockUserEntity.blocked_user = id; - blockUserEntity.status = true; + if (isBlockedUser.delete_date === null) { + throw new HttpException('이미 차단된 유저입니다', 400); + } else { + await this.blockUserRepository.update( + { + blocker: userId, + blocked_user: id, + }, + { delete_date: null }, + ); + } + } else { + const blockUserEntity = new BlockUserEntity(); + blockUserEntity.blocker = userId; + blockUserEntity.blocked_user = id; + blockUserEntity.status = true; - try { - const res = await this.blockUserRepository.save(blockUserEntity); - return res; - } catch (e) { - throw new HttpException('서버 오류입니다', 500); + try { + return await this.blockUserRepository.save(blockUserEntity); + } catch (e) { + throw new HttpException('서버 오류입니다', 500); + } } } @@ -66,7 +72,16 @@ export class UsersBlockService { return blockedUsers; } - remove(id: number) { - return `This action removes a #${id} usersBlock`; + async removeBlockUser(blockedUserId: string, userId: string) { + const blockedUser = await this.blockUserRepository.findOne({ + where: { blocked_user: blockedUserId, blocker: userId }, + }); + if (!blockedUser) { + throw new HttpException('차단된 유저가 없습니다.', 404); + } + await this.blockUserRepository.softDelete({ + blocked_user: blockedUserId, + blocker: userId, + }); } } From 78de52650b8d3f79534be6455f07c077523dc2c7 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 25 Nov 2023 01:03:51 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[BE]=20Feat=20:=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EC=B0=A8=EB=8B=A8=ED=95=B4=EC=A0=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/posts-block/posts-block.controller.ts | 12 ++++-- BE/src/posts-block/posts-block.service.ts | 41 ++++++++++++++++---- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/BE/src/posts-block/posts-block.controller.ts b/BE/src/posts-block/posts-block.controller.ts index 4bb652d..1c6502e 100644 --- a/BE/src/posts-block/posts-block.controller.ts +++ b/BE/src/posts-block/posts-block.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Param, Post } from '@nestjs/common'; +import { Controller, Delete, Get, Param, Post } from '@nestjs/common'; import { PostsBlockService } from './posts-block.service'; @Controller('posts/block') @@ -13,8 +13,12 @@ export class PostsBlockController { @Get() async postsBlockList() { const blockerId: string = 'qwe'; - const blockedPosts = - await this.postsBlockService.findBlockedPosts(blockerId); - return blockedPosts; + return await this.postsBlockService.findBlockedPosts(blockerId); + } + + @Delete(':id') + async blockUserRemove(@Param('id') id: number) { + const userId = 'qwe'; + await this.postsBlockService.removeBlockPosts(id, userId); } } diff --git a/BE/src/posts-block/posts-block.service.ts b/BE/src/posts-block/posts-block.service.ts index 3b1924f..3b9656e 100644 --- a/BE/src/posts-block/posts-block.service.ts +++ b/BE/src/posts-block/posts-block.service.ts @@ -19,27 +19,39 @@ export class PostsBlockService { if (!blockedPost) { throw new HttpException('없는 게시물입니다.', 404); } - const blockPostEntity = new BlockPostEntity(); + const isExist = await this.blockPostRepository.findOne({ where: { blocker: blockerId, blocked_post: postId, }, + withDeleted: true, }); - if (isExist !== null && isExist.status === true) { - throw new HttpException('이미 차단 되었습니다.', 400); + if (isExist) { + if (isExist.delete_date === null) { + throw new HttpException('이미 차단 되었습니다.', 400); + } else { + await this.blockPostRepository.update( + { + blocker: blockerId, + blocked_post: postId, + }, + { delete_date: null }, + ); + } + } else { + const blockPostEntity = new BlockPostEntity(); + blockPostEntity.blocked_post = postId; + blockPostEntity.blocker = blockerId; + blockPostEntity.status = true; + await this.blockPostRepository.save(blockPostEntity); } - blockPostEntity.blocked_post = postId; - blockPostEntity.blocker = blockerId; - blockPostEntity.status = true; - await this.blockPostRepository.save(blockPostEntity); } async findBlockedPosts(blockerId: string) { const blockLists = await this.blockPostRepository.find({ where: { blocker: blockerId, - status: true, }, relations: ['blockedPost'], }); @@ -52,4 +64,17 @@ export class PostsBlockService { }; }); } + + async removeBlockPosts(blockedPostId: number, userId: string) { + const blockedPost = await this.blockPostRepository.findOne({ + where: { blocked_post: blockedPostId, blocker: userId }, + }); + if (!blockedPost) { + throw new HttpException('차단된 유저가 없습니다.', 404); + } + await this.blockPostRepository.softDelete({ + blocked_post: blockedPostId, + blocker: userId, + }); + } } From 3ee0dfb733cc3d3ddb8f3e27948bbfb4739cea64 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 25 Nov 2023 02:12:47 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[BE]=20Feat=20:=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EC=82=AD=EC=A0=9C=EC=8B=9C=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=EB=90=9C=20=EC=B0=A8=EB=8B=A8,=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=20=ED=85=8C=EC=9D=B4=EB=B8=94=EC=9D=98=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EB=8F=84=20=EA=B0=99=EC=9D=B4=20soft=20delete=20?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/post/post.controller.ts | 2 +- BE/src/post/post.service.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/BE/src/post/post.controller.ts b/BE/src/post/post.controller.ts index b8e3b20..0b3cd1b 100644 --- a/BE/src/post/post.controller.ts +++ b/BE/src/post/post.controller.ts @@ -83,7 +83,7 @@ export class PostController { @Delete('/:id') async postRemove(@Param('id') id: number) { - const isRemoved = await this.postService.deletePostById(id); + const isRemoved = await this.postService.removePost(id); if (isRemoved) { return HttpCode(200); diff --git a/BE/src/post/post.service.ts b/BE/src/post/post.service.ts index be0e88f..07fb9cf 100644 --- a/BE/src/post/post.service.ts +++ b/BE/src/post/post.service.ts @@ -226,7 +226,7 @@ export class PostService { } } - async deletePostById(postId: number) { + async removePost(postId: number) { const isDataExists = await this.postRepository.findOne({ where: { id: postId, status: true }, }); @@ -234,8 +234,13 @@ export class PostService { if (!isDataExists) { return false; } else { - await this.postRepository.softDelete({ id: postId }); + await this.deleteCascadingPost(postId); return true; } } + async deleteCascadingPost(postId: number) { + await this.postImageRepository.softDelete({ post_id: postId }); + await this.blockPostRepository.softDelete({ blocked_post: postId }); + await this.postRepository.softDelete({ id: postId }); + } } From bec2555b96870a8eb2ac55913897d0e82c3863b7 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 25 Nov 2023 02:37:08 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[BE]=20Feat=20:=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=EC=8B=9C=20=EA=B4=80=EB=A0=A8=EB=90=9C=20?= =?UTF-8?q?=EC=B0=A8=EB=8B=A8,=20=EC=9D=B4=EB=AF=B8=EC=A7=80,=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=EA=B8=80=20=ED=85=8C=EC=9D=B4=EB=B8=94=EC=9D=98=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=8F=84=20=EA=B0=99=EC=9D=B4=20sof?= =?UTF-8?q?t=20delete=20=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/users/users.controller.ts | 5 ++-- BE/src/users/users.module.ts | 14 +++++++++- BE/src/users/users.service.ts | 44 +++++++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/BE/src/users/users.controller.ts b/BE/src/users/users.controller.ts index 70cd04f..578f93e 100644 --- a/BE/src/users/users.controller.ts +++ b/BE/src/users/users.controller.ts @@ -2,7 +2,6 @@ import { Controller, Get, Post, - Body, Patch, Param, Delete, @@ -50,8 +49,8 @@ export class UsersController { } @Delete(':id') - usersRemove(@Param('id') id: string) { - return this.usersService.removeUser(+id); + async usersRemove(@Param('id') id: string) { + await this.usersService.removeUser(id); } @Patch(':id') diff --git a/BE/src/users/users.module.ts b/BE/src/users/users.module.ts index 06d0fc5..df9dd70 100644 --- a/BE/src/users/users.module.ts +++ b/BE/src/users/users.module.ts @@ -4,9 +4,21 @@ import { UsersController } from './users.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; import { S3Handler } from 'src/utils/S3Handler'; import { UserEntity } from '../entities/user.entity'; +import { PostEntity } from '../entities/post.entity'; +import { PostImageEntity } from '../entities/postImage.entity'; +import { BlockUserEntity } from '../entities/blockUser.entity'; +import { BlockPostEntity } from '../entities/blockPost.entity'; @Module({ - imports: [TypeOrmModule.forFeature([UserEntity])], + imports: [ + TypeOrmModule.forFeature([ + PostEntity, + UserEntity, + PostImageEntity, + BlockUserEntity, + BlockPostEntity, + ]), + ], controllers: [UsersController], providers: [UsersService, S3Handler], }) diff --git a/BE/src/users/users.service.ts b/BE/src/users/users.service.ts index 38de392..3d45b2a 100644 --- a/BE/src/users/users.service.ts +++ b/BE/src/users/users.service.ts @@ -3,16 +3,28 @@ import { CreateUserDto } from './createUser.dto'; import { InjectRepository } from '@nestjs/typeorm'; import { UserEntity } from 'src/entities/user.entity'; import { Repository } from 'typeorm'; -import { UpdatePostDto } from '../post/dto/postUpdate.dto'; import { UpdateUsersDto } from './usersUpdate.dto'; import { S3Handler } from '../utils/S3Handler'; import { hashMaker } from 'src/utils/hashMaker'; +import { PostEntity } from '../entities/post.entity'; +import { PostImageEntity } from '../entities/postImage.entity'; +import { BlockUserEntity } from '../entities/blockUser.entity'; +import { BlockPostEntity } from '../entities/blockPost.entity'; +import { UsersController } from './users.controller'; @Injectable() export class UsersService { constructor( + @InjectRepository(PostEntity) + private postRepository: Repository, @InjectRepository(UserEntity) private userRepository: Repository, + @InjectRepository(PostImageEntity) + private postImageRepository: Repository, + @InjectRepository(BlockUserEntity) + private blockUserRepository: Repository, + @InjectRepository(BlockPostEntity) + private blockPostRepository: Repository, private s3Handler: S3Handler, ) {} @@ -39,8 +51,34 @@ export class UsersService { } } - removeUser(id: number) { - return `This action removes a #${id} user`; + async removeUser(id: string) { + const isDataExists = await this.userRepository.findOne({ + where: { user_hash: id, status: true }, + }); + if (!isDataExists) { + return false; + } else { + await this.deleteCascadingUser(isDataExists); + return true; + } + } + + async deleteCascadingUser(user: UserEntity) { + const postsByUser = await this.postRepository.find({ + where: { user_id: user.id }, + }); + for (const postByUser of postsByUser) { + await this.deleteCascadingPost(postByUser.id); + } + await this.blockPostRepository.softDelete({ blocker: user.user_hash }); + await this.blockUserRepository.softDelete({ blocker: user.user_hash }); + await this.userRepository.softDelete({ id: user.id }); + } + + async deleteCascadingPost(postId: number) { + await this.postImageRepository.softDelete({ post_id: postId }); + await this.blockPostRepository.softDelete({ blocked_post: postId }); + await this.postRepository.softDelete({ id: postId }); } async updateUserById( From f2d128b2734ef39d5cd3ae152270cd86c02ab85f Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 25 Nov 2023 13:45:06 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[BE]=20Feat=20:=20status=20=EC=97=B4=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/entities/blockPost.entity.ts | 3 --- BE/src/entities/blockUser.entity.ts | 3 --- BE/src/entities/post.entity.ts | 3 --- BE/src/entities/user.entity.ts | 3 --- BE/src/post/post.service.ts | 6 ++---- BE/src/posts-block/posts-block.service.ts | 1 - BE/src/users-block/users-block.service.ts | 3 +-- BE/src/users/users.service.ts | 5 ++--- 8 files changed, 5 insertions(+), 22 deletions(-) diff --git a/BE/src/entities/blockPost.entity.ts b/BE/src/entities/blockPost.entity.ts index d156c38..1382360 100644 --- a/BE/src/entities/blockPost.entity.ts +++ b/BE/src/entities/blockPost.entity.ts @@ -17,9 +17,6 @@ export class BlockPostEntity { @PrimaryColumn() blocked_post: number; - @Column({ nullable: false, default: true }) - status: boolean; - @DeleteDateColumn() delete_date: Date; diff --git a/BE/src/entities/blockUser.entity.ts b/BE/src/entities/blockUser.entity.ts index ea1ac0e..8456275 100644 --- a/BE/src/entities/blockUser.entity.ts +++ b/BE/src/entities/blockUser.entity.ts @@ -17,9 +17,6 @@ export class BlockUserEntity { @PrimaryColumn() blocked_user: string; - @Column({ nullable: false, default: true }) - status: boolean; - @DeleteDateColumn() delete_date: Date; diff --git a/BE/src/entities/post.entity.ts b/BE/src/entities/post.entity.ts index a935736..838dae5 100644 --- a/BE/src/entities/post.entity.ts +++ b/BE/src/entities/post.entity.ts @@ -34,9 +34,6 @@ export class PostEntity { @JoinColumn({ name: 'user_id' }) user: UserEntity; - @Column({ type: 'boolean', nullable: false }) - status: boolean; - @Column({ type: 'datetime', nullable: false }) start_date: Date; diff --git a/BE/src/entities/user.entity.ts b/BE/src/entities/user.entity.ts index b7a9ec2..4810200 100644 --- a/BE/src/entities/user.entity.ts +++ b/BE/src/entities/user.entity.ts @@ -49,9 +49,6 @@ export class UserEntity { }) update_date: Date; - @Column({ type: 'tinyint', nullable: false, default: true }) - status: boolean; - @Column({ length: 2048, nullable: true, charset: 'utf8' }) profile_img: string; diff --git a/BE/src/post/post.service.ts b/BE/src/post/post.service.ts index 07fb9cf..0913f48 100644 --- a/BE/src/post/post.service.ts +++ b/BE/src/post/post.service.ts @@ -26,7 +26,7 @@ export class PostService { private s3Handler: S3Handler, ) {} makeWhereOption(query: PostListDto) { - const where = { status: true, is_request: undefined }; + const where = { is_request: undefined }; if (query.requestFilter !== undefined) { where.is_request = query.requestFilter !== 0; } @@ -106,7 +106,6 @@ export class PostService { relations: ['post_images', 'user'], }); - console.log(post); if (post === null) { throw new HttpException('없는 게시물입니다.', 404); } @@ -207,7 +206,6 @@ export class PostService { post.is_request = createPostDto.is_request; post.start_date = createPostDto.start_date; post.end_date = createPostDto.end_date; - post.status = true; post.user_id = user.id; post.thumbnail = imageLocations.length > 0 ? imageLocations[0] : null; // 이미지 추가 @@ -228,7 +226,7 @@ export class PostService { async removePost(postId: number) { const isDataExists = await this.postRepository.findOne({ - where: { id: postId, status: true }, + where: { id: postId }, }); if (!isDataExists) { diff --git a/BE/src/posts-block/posts-block.service.ts b/BE/src/posts-block/posts-block.service.ts index 3b9656e..46dea02 100644 --- a/BE/src/posts-block/posts-block.service.ts +++ b/BE/src/posts-block/posts-block.service.ts @@ -43,7 +43,6 @@ export class PostsBlockService { const blockPostEntity = new BlockPostEntity(); blockPostEntity.blocked_post = postId; blockPostEntity.blocker = blockerId; - blockPostEntity.status = true; await this.blockPostRepository.save(blockPostEntity); } } diff --git a/BE/src/users-block/users-block.service.ts b/BE/src/users-block/users-block.service.ts index a375ed1..ea9d674 100644 --- a/BE/src/users-block/users-block.service.ts +++ b/BE/src/users-block/users-block.service.ts @@ -42,7 +42,6 @@ export class UsersBlockService { const blockUserEntity = new BlockUserEntity(); blockUserEntity.blocker = userId; blockUserEntity.blocked_user = id; - blockUserEntity.status = true; try { return await this.blockUserRepository.save(blockUserEntity); @@ -54,7 +53,7 @@ export class UsersBlockService { async getBlockUser(id: string) { const res = await this.blockUserRepository.find({ - where: { blocker: id, status: true }, + where: { blocker: id }, relations: ['blockedUser'], }); diff --git a/BE/src/users/users.service.ts b/BE/src/users/users.service.ts index 3d45b2a..347b362 100644 --- a/BE/src/users/users.service.ts +++ b/BE/src/users/users.service.ts @@ -35,14 +35,13 @@ export class UsersService { userEntity.OAuth_domain = createUserDto.OAuth_domain; userEntity.profile_img = imageLocation; userEntity.user_hash = hashMaker(createUserDto.nickname).slice(0, 8); - userEntity.status = true; const res = await this.userRepository.save(userEntity); return res; } async findUserById(userId: string) { const user: UserEntity = await this.userRepository.findOne({ - where: { user_hash: userId, status: true }, + where: { user_hash: userId }, }); if (user) { return { nickname: user.nickname, profile_img: user.profile_img }; @@ -53,7 +52,7 @@ export class UsersService { async removeUser(id: string) { const isDataExists = await this.userRepository.findOne({ - where: { user_hash: id, status: true }, + where: { user_hash: id }, }); if (!isDataExists) { return false; From 1b8f951b8a4ee16d42627e696dcdfcf482efbdcf Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 25 Nov 2023 14:00:10 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[BE]=20Feat=20:=20user=20hash=20=EC=9D=B8?= =?UTF-8?q?=EC=BD=94=EB=94=A9=20base64url=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/utils/hashMaker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BE/src/utils/hashMaker.ts b/BE/src/utils/hashMaker.ts index 3066497..cd596d8 100644 --- a/BE/src/utils/hashMaker.ts +++ b/BE/src/utils/hashMaker.ts @@ -4,5 +4,5 @@ export const hashMaker = (nickname: string) => { return crypto .createHash('sha256') .update(nickname + new Date().getTime()) - .digest('base64'); + .digest('base64url'); }; From 2bffe803b374abb6b3de88dbabae7635aafef4fa Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 25 Nov 2023 14:18:47 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[BE]=20Feat=20:=20=EC=B0=A8=EB=8B=A8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=EC=97=90=EC=84=9C=20update=EC=99=80=20save?= =?UTF-8?q?=EB=A1=9C=20=EB=B6=84=EB=A6=AC=ED=95=9C=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=9D=84=20save=EB=A1=9C=20=EB=B3=91=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/posts-block/posts-block.service.ts | 26 +++++++----------- BE/src/users-block/users-block.service.ts | 33 +++++++++-------------- 2 files changed, 21 insertions(+), 38 deletions(-) diff --git a/BE/src/posts-block/posts-block.service.ts b/BE/src/posts-block/posts-block.service.ts index 46dea02..191eca7 100644 --- a/BE/src/posts-block/posts-block.service.ts +++ b/BE/src/posts-block/posts-block.service.ts @@ -27,24 +27,16 @@ export class PostsBlockService { }, withDeleted: true, }); - if (isExist) { - if (isExist.delete_date === null) { - throw new HttpException('이미 차단 되었습니다.', 400); - } else { - await this.blockPostRepository.update( - { - blocker: blockerId, - blocked_post: postId, - }, - { delete_date: null }, - ); - } - } else { - const blockPostEntity = new BlockPostEntity(); - blockPostEntity.blocked_post = postId; - blockPostEntity.blocker = blockerId; - await this.blockPostRepository.save(blockPostEntity); + + if (isExist !== null && isExist.delete_date === null) { + throw new HttpException('이미 차단 되었습니다.', 400); } + + const blockPostEntity = new BlockPostEntity(); + blockPostEntity.blocked_post = postId; + blockPostEntity.blocker = blockerId; + blockPostEntity.delete_date = null; + await this.blockPostRepository.save(blockPostEntity); } async findBlockedPosts(blockerId: string) { diff --git a/BE/src/users-block/users-block.service.ts b/BE/src/users-block/users-block.service.ts index ea9d674..8be4559 100644 --- a/BE/src/users-block/users-block.service.ts +++ b/BE/src/users-block/users-block.service.ts @@ -26,28 +26,19 @@ export class UsersBlockService { where: { blocked_user: id, blocker: userId }, withDeleted: true, }); - if (isBlockedUser) { - if (isBlockedUser.delete_date === null) { - throw new HttpException('이미 차단된 유저입니다', 400); - } else { - await this.blockUserRepository.update( - { - blocker: userId, - blocked_user: id, - }, - { delete_date: null }, - ); - } - } else { - const blockUserEntity = new BlockUserEntity(); - blockUserEntity.blocker = userId; - blockUserEntity.blocked_user = id; - try { - return await this.blockUserRepository.save(blockUserEntity); - } catch (e) { - throw new HttpException('서버 오류입니다', 500); - } + if (isBlockedUser !== null && isBlockedUser.delete_date === null) { + throw new HttpException('이미 차단된 유저입니다', 400); + } + const blockUserEntity = new BlockUserEntity(); + blockUserEntity.blocker = userId; + blockUserEntity.blocked_user = id; + blockUserEntity.delete_date = null; + + try { + return await this.blockUserRepository.save(blockUserEntity); + } catch (e) { + throw new HttpException('서버 오류입니다', 500); } }