Skip to content

Commit aaea83e

Browse files
committed
update save message and get messages
1 parent 1f2ab88 commit aaea83e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

backend/src/chat/chat.resolver.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class ChatResolver {
2727
if (chunk) {
2828
await this.chatService.saveMessage(
2929
input.id,
30+
chunk.id,
3031
chunk.choices[0].delta.content,
3132
);
3233
yield chunk;
@@ -38,6 +39,13 @@ export class ChatResolver {
3839
}
3940
}
4041

42+
@Query(() => Message, { nullable: true })
43+
async getMessageDetail(
44+
@Args('messageId') messageId: string,
45+
): Promise<Message> {
46+
return this.chatService.getMessageById(messageId);
47+
}
48+
4149
@Query(() => [Message])
4250
async getChatHistory(@Args('chatId') chatId: string): Promise<Message[]> {
4351
return this.chatService.getChatHistory(chatId);

backend/src/chat/chat.service.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ export class ChatService {
158158
return chat ? chat.messages : [];
159159
}
160160

161+
async getMessageById(messageId: string): Promise<Message> {
162+
return await this.messageRepository.findOne({
163+
where: { id: messageId },
164+
});
165+
}
166+
161167
async getChatDetails(chatId: string): Promise<Chat> {
162168
return this.chatRepository.findOne({
163169
where: { id: chatId },
@@ -208,13 +214,18 @@ export class ChatService {
208214
return null;
209215
}
210216

211-
async saveMessage(chatId: string, messageContent: string): Promise<Message> {
217+
async saveMessage(
218+
chatId: string,
219+
chunkId: string,
220+
messageContent: string,
221+
): Promise<Message> {
212222
// Find the chat instance
213223
const chat = await this.chatRepository.findOne({ where: { id: chatId } });
214224
if (!chat) throw new Error('Chat not found');
215225

216226
// Create a new message associated with the chat
217227
const message = this.messageRepository.create({
228+
id: chunkId,
218229
content: messageContent,
219230
role: Role.Model,
220231
chat,

0 commit comments

Comments
 (0)