From 5a1212acf68c1184f2b091b20efe7bbc08362662 Mon Sep 17 00:00:00 2001 From: Sawit Koseeyaumporn Date: Tue, 26 Nov 2024 00:37:05 +0700 Subject: [PATCH] fix: messageController.ts senderID --- src/controllers/messageController.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/controllers/messageController.ts b/src/controllers/messageController.ts index 8bf7dae..9da19f5 100644 --- a/src/controllers/messageController.ts +++ b/src/controllers/messageController.ts @@ -89,7 +89,7 @@ export const messageController = new Elysia({ prefix: "/message" }) } // Get the latest message from each conversation - const latestMessages = await prisma.$queryRaw` + const latestMessages: any[] = await prisma.$queryRaw` SELECT m1.* FROM @@ -111,6 +111,17 @@ export const messageController = new Elysia({ prefix: "/message" }) m1.Timestamp = m2.maxTimestamp `; + // get the user information of the other user in the conversation + for (let i = 0; i < latestMessages.length; i++) { + const message = latestMessages[i]; + const otherUser = await prisma.user.findUnique({ + where: { UserID: message.SenderID === userID ? message.ReceiverID : message.SenderID }, + }); + + latestMessages[i].otherUser = otherUser; + } + + return latestMessages; })