From 1cc917aa578aea532f27f7aea58c5abe1a2428de Mon Sep 17 00:00:00 2001 From: Ahn Jiwan Date: Mon, 4 Dec 2023 18:56:04 +0900 Subject: [PATCH] =?UTF-8?q?:bug:=20fix:=20Chat=20Dto=20JSON=20=ED=98=95?= =?UTF-8?q?=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=EC=8B=9D=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20(#66)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/chat/chat.gateway.ts | 19 ++++++------------- src/infra/entities/message.entity.ts | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/domain/chat/chat.gateway.ts b/src/domain/chat/chat.gateway.ts index 344af01..f64fe04 100644 --- a/src/domain/chat/chat.gateway.ts +++ b/src/domain/chat/chat.gateway.ts @@ -8,12 +8,9 @@ import { import { Server, Socket } from 'socket.io'; import { UseGuards } from '@nestjs/common'; import { JwtServiceAuthGuard } from '../../auth/guards/jwt-service-auth.guard'; -import { InjectRepository } from '@nestjs/typeorm'; -import { ChatMessage } from '../../infra/entities/message.entity'; import { ChatService } from './chat.service'; import { CreateChatDto } from './dto/create-chat.dto'; -@UseGuards(JwtServiceAuthGuard) @WebSocketGateway({ namespace: 'chat', cors: true, @@ -22,10 +19,7 @@ export class ChatGateway { @WebSocketServer() server: Server; - constructor( - @InjectRepository(ChatMessage) - private readonly chatService: ChatService, - ) {} + constructor(private readonly chatService: ChatService) {} @SubscribeMessage('joinFamily') async handleJoinRoom( @@ -38,17 +32,16 @@ export class ChatGateway { @SubscribeMessage('sendMessage') async handleMessage( - @MessageBody() - data: { createChatDto: CreateChatDto }, + @MessageBody() createChatDto: CreateChatDto, @ConnectedSocket() client: Socket, ) { const createDate = new Date(); - await this.chatService.saveChat(data.createChatDto, createDate); + await this.chatService.saveChat(createChatDto, createDate); // 다른 가족 구성원에게 메시지 전송 - this.server.to(data.createChatDto.familyId).emit('receiveMessage', { - familyMemberId: data.createChatDto.familyMemberId, - message: data.createChatDto.message, + this.server.to(createChatDto.familyId).emit('receiveMessage', { + familyMemberId: createChatDto.familyMemberId, + message: createChatDto.message, createdAt: createDate, // 메시지가 저장된 시간 }); } diff --git a/src/infra/entities/message.entity.ts b/src/infra/entities/message.entity.ts index b7534a3..a3d4887 100644 --- a/src/infra/entities/message.entity.ts +++ b/src/infra/entities/message.entity.ts @@ -8,7 +8,7 @@ import { import { Family } from './family.entity'; import { FamilyMember } from './family-member.entity'; -@Entity() +@Entity('chat_message', { schema: 'family_app_db' }) export class ChatMessage { @PrimaryGeneratedColumn({ type: 'int', name: 'ID' }) id: number;