Skip to content

Commit

Permalink
Feat : 채팅방 나가기 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
namewhat99 committed Jan 9, 2024
1 parent a8b7c9e commit a5f214a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions BE/src/chat/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export class ChatController {
return await this.chatService.unreadChat(userId);
}

@Get('leave/:id')
@UseGuards(AuthGuard)
async leaveChatRoom(@Param('id') id: number, @UserHash() userId: string) {
return await this.chatService.leaveChatRoom(id, userId);
}

@Get()
async testPush(@Body() body) {
await this.fcmHandler.sendPush(body.user, {
Expand Down
14 changes: 14 additions & 0 deletions BE/src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,18 @@ export class ChatService {
return null;
}
}

async leaveChatRoom(roomId: number, userId: string) {
const room = await this.chatRoomRepository.findOne({
where: { id: roomId },
});

if (room.writer === userId) {
room.writer_left = true;
} else if (room.user === userId) {
room.user_left = true;
}

await this.chatRoomRepository.save(room);
}
}

0 comments on commit a5f214a

Please sign in to comment.