From 9a3c629b25ddff5e4a2177be8659550d0e5cccce Mon Sep 17 00:00:00 2001 From: NaayoungKwon Date: Fri, 25 Nov 2022 02:12:17 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=9A=94=EC=B2=AD=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=EC=9D=98=20=EA=B6=8C=ED=95=9C=20=ED=99=95=EC=9D=B8=20?= =?UTF-8?q?#95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apps/api/src/community/community.controller.ts | 9 ++++----- server/apps/api/src/community/community.service.ts | 14 +++++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/server/apps/api/src/community/community.controller.ts b/server/apps/api/src/community/community.controller.ts index bfa59d28..36ce17a1 100644 --- a/server/apps/api/src/community/community.controller.ts +++ b/server/apps/api/src/community/community.controller.ts @@ -52,11 +52,10 @@ export class CommunityController { @Req() req: any, ) { try { - const _id = req.user._id; - await this.communityService.appendParticipantsToCommunity({ - ...appendUsersToCommunityDto, - requestUser_id: _id, - }); + await this.communityService.appendParticipantsToCommunity( + req.user, + appendUsersToCommunityDto, + ); return responseForm(200, { message: '커뮤니티 사용자 추가 완료' }); } catch (error) { this.logger.error(JSON.stringify(error.response)); diff --git a/server/apps/api/src/community/community.service.ts b/server/apps/api/src/community/community.service.ts index 7e68fd05..ca3770ec 100644 --- a/server/apps/api/src/community/community.service.ts +++ b/server/apps/api/src/community/community.service.ts @@ -7,6 +7,7 @@ import { ModifyCommunityDto, DeleteCommunityDto, } from './dto'; +import { IsUserInCommunity } from '@community/helper/checkUserIsInCommunity'; @Injectable() export class CommunityService { @@ -25,8 +26,14 @@ export class CommunityService { return community; } - async appendParticipantsToCommunity(appendUsersToCommunityDto: AppendUsersToCommunityDto) { + async appendParticipantsToCommunity( + reqUser, + appendUsersToCommunityDto: AppendUsersToCommunityDto, + ) { const communityId = appendUsersToCommunityDto.community_id; + if (!IsUserInCommunity(reqUser, communityId)) { + throw new BadRequestException(`커뮤니티에 속하지 않는 사용자는 요청할 수 없습니다.`); + } const newCommunity = this.makeCommunityObj(communityId); await Promise.all( // 사용자 document 검증 (올바른 사용자인지, 해당 사용자가 이미 커뮤니티에 참여하고 있는건 아닌지) @@ -36,10 +43,7 @@ export class CommunityService { throw new BadRequestException( `커뮤니티에 추가를 요청한 사용자 _id(${user_id})가 올바르지 않습니다.`, ); - } else if ( - (user.communities ?? false) && - Array.from(user.communities.keys()).includes(communityId) - ) { + } else if (IsUserInCommunity(user, communityId)) { throw new BadRequestException(`이미 커뮤니티에 추가된 사용자 입니다.`); } }),