diff --git a/src/group/group.service.ts b/src/group/group.service.ts index 6495259..8ce3051 100644 --- a/src/group/group.service.ts +++ b/src/group/group.service.ts @@ -44,26 +44,13 @@ export class GroupService { return this.groupRepository.delete(groupId); } - async deleteMember(groupId: string, memberId: string): Promise { - const group = (await this.groupRepository.findOne(groupId)) as Group; - if (group.members.includes(memberId)) { - group.members = group.members.filter((member) => member !== memberId); - } - await this.groupRepository.update(groupId, group); - } - async deleteMembers(groupId: string, memberIds: string[]): Promise { const group = (await this.groupRepository.findOne(groupId)) as Group; const groupMembers = group.members; - if ( - Array.isArray(memberIds) && - memberIds.every((item) => typeof item === 'string') - ) { - group.members = groupMembers.filter( - (member) => !memberIds.includes(member), - ); - } + group.members = groupMembers.filter( + (member) => !memberIds.find((id) => id === member), + ); await this.groupRepository.update(groupId, group); } diff --git a/src/member/member.service.ts b/src/member/member.service.ts index f946223..74ec67b 100644 --- a/src/member/member.service.ts +++ b/src/member/member.service.ts @@ -70,11 +70,10 @@ export class MemberService { } async delete(groupId: string, memberId: string): Promise { - const memberIds: string[] = [memberId]; - if (!this.validateMemberIds(memberIds)) throw new NotFoundException(); + if (!this.validateMemberIds([memberId])) throw new NotFoundException(); - this.memberRepository.delete(memberIds); - await this.groupService.deleteMember(groupId, memberId); + this.memberRepository.delete([memberId]); + await this.groupService.deleteMembers(groupId, [memberId]); } async deleteGroupMembers(