Skip to content

Commit

Permalink
fix: messageController.ts senderID
Browse files Browse the repository at this point in the history
  • Loading branch information
Celesca committed Nov 25, 2024
1 parent 92f6972 commit 5a1212a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/controllers/messageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
})

Expand Down

0 comments on commit 5a1212a

Please sign in to comment.