Skip to content

Commit

Permalink
fix: getChatRoom with deleted user
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeahxx19 committed Nov 18, 2023
1 parent 654eb5f commit 3ecb8f7
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,19 @@ export class ChatService {
const otherUserInfo = await this.socketUserModel.findOne({
userId: otherUser.userId,
});
const latestChat = await this.chattingModel
.find({ roomId: room.id })
.sort({ createdAt: -1 })
.limit(1);

return RoomInfoDto.ToDto(
room.id,
user.hasRead,
otherUserInfo,
latestChat[0],
);
if (otherUserInfo) {
const latestChat = await this.chattingModel
.find({ roomId: room.id })
.sort({ createdAt: -1 })
.limit(1);

return RoomInfoDto.ToDto(
room.id,
user.hasRead,
otherUserInfo,
latestChat[0],
);
}
}

async getChats(roomId: string, userId: number) {
Expand Down

0 comments on commit 3ecb8f7

Please sign in to comment.