Skip to content

Commit

Permalink
fix: 65acaee includes->find
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoxong committed Apr 19, 2024
1 parent 65acaee commit d1e16b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
19 changes: 3 additions & 16 deletions src/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,13 @@ export class GroupService {
return this.groupRepository.delete(groupId);
}

async deleteMember(groupId: string, memberId: string): Promise<void> {
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<void> {
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);
}
Expand Down
7 changes: 3 additions & 4 deletions src/member/member.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ export class MemberService {
}

async delete(groupId: string, memberId: string): Promise<void> {
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(
Expand Down

0 comments on commit d1e16b8

Please sign in to comment.