Skip to content

Commit

Permalink
Feature(hyunsoo/chat): 채팅방 초대 거절 기능 구현 modern-agile-team#92
Browse files Browse the repository at this point in the history
  • Loading branch information
KimSoo committed Feb 22, 2023
1 parent d79f693 commit cb924cc
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
18 changes: 18 additions & 0 deletions main-project/src/chats/chats-controller.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,22 @@ export class ChatsControllerService {
throw new InternalServerErrorException(`알림 삭제에 실패했습니다.`);
}
}

async rejecteInvitation(
manager: EntityManager,
userNo: number,
chatRoomNo: number,
{ senderNo, type }: AcceptInvitationDto,
): Promise<void> {
const noticeNo: number = await this.checkChatNotice(
userNo,
senderNo,
chatRoomNo,
type,
);
if (!noticeNo) {
throw new NotFoundException(`초대 정보가 존재하지 않습니다.`);
}
await this.deleteNotice(manager, noticeNo);
}
}
22 changes: 21 additions & 1 deletion main-project/src/chats/chats.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { APIResponse } from 'src/common/interface/interface';
import { TransactionInterceptor } from 'src/common/interceptor/transaction-interceptor';
import { TransactionDecorator } from 'src/common/decorator/transaction-manager.decorator';
import { EntityManager } from 'typeorm';
import { UseGuards } from '@nestjs/common/decorators';
import { Delete, UseGuards } from '@nestjs/common/decorators';
import { JwtAuthGuard } from 'src/common/guards/jwt-auth.guard';
import { GetUser } from 'src/common/decorator/get-user.decorator';
import { ApiGetPreviousChatLog } from './swagger/get-previous-chat-log.decorator';
Expand All @@ -28,6 +28,7 @@ import { ApiInviteUser } from './swagger/invite-user.decorator';
import { ApiAcceptInvitation } from './swagger/accept-invitation.decorator';
import { APiUploadFile } from './swagger/upload-file.decorator';
import { ApiCreateChatRoom } from './swagger/create-chat-room.decorator';
import { ApiRejecteInvitation } from './swagger/rejected-invitation.decorator';

@Controller('chats')
@ApiTags('채팅 APi')
Expand Down Expand Up @@ -130,6 +131,25 @@ export class ChatsController {
};
}

@Delete('/:chatRoomNo/invitation')
@ApiRejecteInvitation()
@UseGuards(JwtAuthGuard)
@UseInterceptors(TransactionInterceptor)
async rejecteInvitation(
@GetUser() userNo: number,
@TransactionDecorator() manager: EntityManager,
@Param('chatRoomNo', ParseIntPipe) chatRoomNo: number,
@Body() invitation: AcceptInvitationDto,
): Promise<APIResponse> {
await this.chatControllerService.rejecteInvitation(
manager,
userNo,
chatRoomNo,
invitation,
);
return { msg: '채팅방 초대 거절 성공' };
}

@Post('/:chatRoomNo/files')
@APiUploadFile()
@UseInterceptors(FilesInterceptor('files', 10)) // 10은 최대파일개수
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function ApiAcceptInvitation() {
return applyDecorators(
ApiOperation({
summary: '채팅방 초대 수락 ',
description: '유저 번호, 타입, 채팅방 번호를 통해 초대 수락',
description: '유저 번호, notice타입, 채팅방 번호를 통해 초대 수락',
}),
ApiBearerAuth(),
ApiBody({
Expand Down
50 changes: 50 additions & 0 deletions main-project/src/chats/swagger/rejected-invitation.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { applyDecorators } from '@nestjs/common';
import {
ApiBearerAuth,
ApiBody,
ApiNotFoundResponse,
ApiOkResponse,
ApiOperation,
} from '@nestjs/swagger';
import { SwaggerApiResponse } from 'src/common/swagger/api-response.swagger';

export function ApiRejecteInvitation() {
return applyDecorators(
ApiOperation({
summary: '채팅방 초대 거절',
description: '유저 번호, notice타입, 채팅방 번호를 통해 초대 거절',
}),
ApiBearerAuth(),
ApiBody({
schema: {
type: 'object',
properties: {
senderNo: {
type: 'number',
minLength: 1,
example: 9,
nullable: false,
description: '초대한 유저의 userNo',
},
type: {
type: 'number',
maxLength: 1,
nullable: false,
description: '알람 typeNo',
},
},
},
}),
ApiOkResponse(
SwaggerApiResponse.success('채팅방 초대 거절', '채팅방 초대 거절 성공'),
),
ApiNotFoundResponse(
SwaggerApiResponse.exception([
{
name: 'noticeNotFound',
example: { msg: '초대 정보가 존재하지 않습니다.' },
},
]),
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function ApiSendFriendRequest() {
},
{
name: 'invalidRecipient',
exampel: { msg: '잘못된 요청입니다.' },
example: { msg: '잘못된 요청입니다.' },
},
]),
),
Expand Down

0 comments on commit cb924cc

Please sign in to comment.