Skip to content

Commit

Permalink
added existingConvo check
Browse files Browse the repository at this point in the history
  • Loading branch information
arogya01 committed Sep 16, 2024
1 parent 6322a2d commit 10087b1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/modules/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,41 @@ export const createConversation = async (
},
groupName?: string
) => {
console.log('service group name');
console.log({ participants, message, groupName });
// if between the two user, then no need to create the conversation name,

const existingConversation = await prisma.conversation.findFirst({
where: {
participant: {
every: {
userId: { in: participants },
},
},
AND: [
{
participant: {
every: {
userId: { in: participants },
},
},
},
{
participant: {
none: {
userId: { notIn: participants },
},
},
},
],
},
});

if (existingConversation) {
throw new Error("Conversation already exists between these two participants");
}


try {
const result = await prisma.conversation.create({
data: {
Expand Down

0 comments on commit 10087b1

Please sign in to comment.