From 1a51e32ff40f083fc54f993001d3e378f69f19f9 Mon Sep 17 00:00:00 2001 From: Devin Alvaro <devin.alvaro@gmail.com> Date: Tue, 21 Nov 2017 17:45:56 +0700 Subject: [PATCH] Add findChat() method to ChatData --- mongoose.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mongoose.js b/mongoose.js index 89803f9..781be29 100644 --- a/mongoose.js +++ b/mongoose.js @@ -41,4 +41,23 @@ class ChatData { } }) } + + findChat (firstParticipantId, secondParticipantId) { + var participantIds = [ firstParticipantId, secondParticipantId ] + participantIds.sort() + + this.ChatModel.findOne({ participant_ids: participantIds }, function (err, result) { + if (err) { + return console.error(err) + } + + if (result) { + var chats = result.chats + + chats.forEach(function (chat) { + console.log(chat) + }) + } + }) + } } -- GitLab