Skip to content

Commit 19eb895

Browse files
author
Rishabh Garg
committed
Corrected create conversation query
1 parent 2c51924 commit 19eb895

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/controllers/conversation.controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ export class ConversationController {
9090
try {
9191
let conversationBody = request.body;
9292
conversationBody.members.push(request['user']._id);
93-
const conversation = await this.conversationRepository.create(request.body);
93+
const conversationAray = await this.conversationRepository.retrieve({ members: { "$all": conversationBody.members } });
94+
let conversation;
95+
if (conversationAray.length) {
96+
conversation = conversationAray[0];
97+
} else {
98+
conversation = await this.conversationRepository.create(request.body);
99+
}
94100
response.send(CumtomResponse.success(conversation, 'Conversation created'));
95101
} catch (error) {
96102
throw CumtomResponse.serverError(error, 'Error');

0 commit comments

Comments
 (0)