Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/chat/repositories/chat.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class ChatRepository {

// ์ฑ„ํŒ…๋ฐฉ์„ ๋‚˜๊ฐ”์œผ๋ฉด ๊ทธ ์ดํ›„์˜ ๋ฉ”์„ธ์ง€๋งŒ ์กฐํšŒ
if (leftAt) {
whereConditions.created_at = { gt: leftAt };
whereConditions.sent_at = { gt: leftAt };
}

const [messages, totalCount] = await Promise.all([
Expand Down Expand Up @@ -105,6 +105,7 @@ export class ChatRepository {
return {
messages: actualMessages,
totalCount,
hasMore: hasNextPage,
};
}

Expand Down Expand Up @@ -258,14 +259,16 @@ export class ChatRepository {
}

// == ๋ฉ”์„ธ์ง€ ์ €์žฅ
async saveMessage(
roomId: number,
senderId: number,
content: string,
files: { url: string; contentType: AttachmentType; name: string; size: number }[]
) {

return prisma.chatMessage.create({
async saveMessage(
roomId: number,
senderId: number,
content: string,
files: { url: string; contentType: AttachmentType; name: string; size: number }[]
) {
// ํŠธ๋žœ์žญ์…˜์œผ๋กœ ๋ฉ”์„ธ์ง€ ์ƒ์„ฑ๊ณผ ์ฑ„ํŒ…๋ฐฉ ์—…๋ฐ์ดํŠธ๋ฅผ ๋ฌถ์–ด์„œ ์ฒ˜๋ฆฌ
return prisma.$transaction(async (tx) => {
// 1. ๋ฉ”์„ธ์ง€ ์ƒ์„ฑ
const savedMessage = await tx.chatMessage.create({
data: {
room_id: roomId,
sender_id: senderId,
Expand All @@ -290,8 +293,14 @@ export class ChatRepository {
attachments: true,
},
});
}


}
// 2. ์ฑ„ํŒ…๋ฐฉ์˜ ๋งˆ์ง€๋ง‰ ๋ฉ”์„ธ์ง€ ID ์—…๋ฐ์ดํŠธ
await tx.chatRoom.update({
where: { room_id: roomId },
data: { last_message_id: savedMessage.message_id },
});

return savedMessage;
});
}
}
8 changes: 3 additions & 5 deletions src/chat/services/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ export class ChatService {
this.chatRepo.findMessagesByRoomId(roomId, cursor, limit, myId),
updateReadStatus
]);

// ํŽ˜์ด์ง€๋„ค์ด์…˜
const hasMore = messageInfo.messages.length > limit;
const messages = hasMore ? messageInfo.messages.slice(0, limit) : messageInfo.messages;

const hasMore = messageInfo.hasMore;
const messages = messageInfo.messages;

return ChatRoomDetailResponseDto.from({
roomDetail,
Expand All @@ -88,7 +87,6 @@ export class ChatService {
filter,
search
});


// ํŽ˜์ด์ง€๋„ค์ด์…˜
const hasMore = roomList.rooms.length > limit;
Expand Down
Loading