more logic for getting conversation if it's not there but should be

This commit is contained in:
talksik
2022-06-11 12:40:17 -05:00
parent 298a989cd9
commit 10ac1626ab
5 changed files with 80 additions and 16 deletions
@@ -3,6 +3,19 @@ import { ObjectId } from 'mongodb';
import { collections } from './database.service';
export default class ConversationService {
static async getConversationById(conversationId: string) {
const query = { _id: new ObjectId(conversationId) };
const res = await collections.conversations?.findOne(query);
// exists
if (res?._id) {
return res as Conversation;
}
return undefined;
}
static async createConversation(newConversation: Conversation) {
return await collections.conversations?.insertOne(newConversation);
}