Skip to content

Commit

Permalink
🐛 fix: Chat Dto JSON 형식으로 인식하도록 수정 (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
synoti21 committed Dec 4, 2023
1 parent 0919476 commit 1cc917a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions src/domain/chat/chat.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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, // 메시지가 저장된 시간
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/infra/entities/message.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1cc917a

Please sign in to comment.