From 27d9f327aad7da0696eb6d2813f5f7fff8b1dd08 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: Sun, 21 Jan 2024 11:46:04 +0900 Subject: [PATCH] =?UTF-8?q?Feat=20:=20=EC=B1=84=ED=8C=85=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EC=B0=A8=EB=8B=A8=20=EC=97=AC=EB=B6=80=20=EC=B2=B4=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/users-block/users-block.controller.ts | 5 ++++ BE/src/users-block/users-block.service.ts | 31 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/BE/src/users-block/users-block.controller.ts b/BE/src/users-block/users-block.controller.ts index 911ed5d..0c52fa8 100644 --- a/BE/src/users-block/users-block.controller.ts +++ b/BE/src/users-block/users-block.controller.ts @@ -20,6 +20,11 @@ export class UsersBlockController { return this.usersBlockService.getBlockUser(userId); } + @Get('/:id') + async blockUserCheck(@Param('id') id: string, @UserHash() userId: string) { + return await this.usersBlockService.checkBlockUser(id, userId); + } + @Post('/:id') async blockUserAdd(@Param('id') id: string, @UserHash() userId: string) { await this.usersBlockService.addBlockUser(id, userId); diff --git a/BE/src/users-block/users-block.service.ts b/BE/src/users-block/users-block.service.ts index f588828..e466af9 100644 --- a/BE/src/users-block/users-block.service.ts +++ b/BE/src/users-block/users-block.service.ts @@ -46,6 +46,37 @@ export class UsersBlockService { return await this.blockUserRepository.save(blockUserEntity); } + async checkBlockUser(oppId: string, userId: string) { + const isExistUser = await this.userRepository.findOne({ + where: { user_hash: oppId }, + withDeleted: true, + }); + + if (!isExistUser) { + throw new HttpException('존재하지 않는 유저입니다', 404); + } + + const checkBlock = await this.blockUserRepository.findOne({ + where: { blocker: userId, blocked_user: oppId }, + withDeleted: true, + }); + + if (checkBlock !== null) { + return { block: 'block' }; + } + + const checkBlocked = await this.blockUserRepository.findOne({ + where: { blocker: oppId, blocked_user: userId }, + withDeleted: true, + }); + + if (checkBlocked !== null) { + return { block: 'blocked' }; + } + + return { block: 'none' }; + } + async getBlockUser(id: string) { const res = await this.blockUserRepository.find({ where: { blocker: id },