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 3ecb8f7 commit 130cc56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 11 additions & 13 deletions src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,17 @@ export class ChatService {
const otherUserInfo = await this.socketUserModel.findOne({
userId: otherUser.userId,
});
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],
);
}
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
6 changes: 4 additions & 2 deletions src/dtos/chat.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ export class RoomInfoDto {
return {
roomId: roomId,
hasRead: hasRead,
nickname: otherUserSchema.userNickname,
sex: otherUserSchema.userSex,
nickname: otherUserSchema
? otherUserSchema.userNickname
: '탈퇴한 사용자',
sex: otherUserSchema ? otherUserSchema.userSex : null,
latest_chat: chattingSchema ? chattingSchema.chat : null,
latest_time: chattingSchema ? chattingSchema.createdAt : null,
};
Expand Down

0 comments on commit 130cc56

Please sign in to comment.