Skip to content

Commit

Permalink
fix: create DeleteMemberDto
Browse files Browse the repository at this point in the history
  • Loading branch information
w8385 committed May 15, 2024
1 parent dedae61 commit 9485058
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/group/dto/delete-member.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApiProperty } from '@nestjs/swagger';

export class DeleteMemberDto {
@ApiProperty({
required: true,
description: '멤버 아이디 목록',
example: ['663fb4d6c30e2acec791595c', '663fb4d6c30e2acec791595e'],
})
readonly memberIds: string[];
}
6 changes: 4 additions & 2 deletions src/group/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { GetTransactionsPeriodDto } from '../transaction/dto/get-transaction-per
import { UploadTransactionDto } from '../transaction/dto/upload-transaction-dto';
import { Transaction } from '../transaction/transaction.decorators';
import { CreateGroupDto } from './dto/create-group.dto';
import { DeleteMemberDto } from './dto/delete-member.dto';
import { UpdateGroupDto } from './dto/update-group.dto';
import { UploadGroupDto } from './dto/upload-group.dto';
import { Group } from './group.decorators';
Expand Down Expand Up @@ -280,15 +281,16 @@ export class GroupController {

@Delete(':groupId/member')
@Member()
@ApiBody({ type: DeleteMemberDto })
@ApiOperation({
summary: '모임 멤버 삭제',
description: '특정 모임의 멤버를 삭제합니다.',
})
deleteMembers(
@Param('groupId') groupId: string,
@Body() memberIds: string[],
@Body() deleteMemberDto: DeleteMemberDto,
) {
return this.groupService.deleteMembers(groupId, memberIds);
return this.groupService.deleteMembers(groupId, deleteMemberDto);
}

@Delete(':groupId/event/:eventId')
Expand Down
7 changes: 6 additions & 1 deletion src/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MemberService } from '../member/member.service';
import { GetTransactionsPeriodDto } from '../transaction/dto/get-transaction-period-dto';
import { TransactionService } from '../transaction/transaction.service';
import { CreateGroupDto } from './dto/create-group.dto';
import { DeleteMemberDto } from './dto/delete-member.dto';
import { UpdateGroupDto } from './dto/update-group.dto';
import { Group } from './entities/group.entity';
import { GroupRepository } from './group.repository';
Expand Down Expand Up @@ -200,9 +201,13 @@ export class GroupService {
return this.groupRepository.delete(groupId);
}

async deleteMembers(groupId: string, memberIds: string[]): Promise<void> {
async deleteMembers(
groupId: string,
deleteMemberDto: DeleteMemberDto,
): Promise<void> {
const group = await this.groupRepository.findOne(groupId);
const groupMembers = group.members;
const memberIds = deleteMemberDto.memberIds;

group.members = groupMembers.filter(
(member) => !memberIds.includes(member),
Expand Down

0 comments on commit 9485058

Please sign in to comment.