cleaning up api and testing getting conversations and such
This commit is contained in:
@@ -1,8 +1,22 @@
|
||||
import Conversation from '@nirvana/core/models/conversation.model';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { collections } from './database.service';
|
||||
|
||||
export default class ConversationService {
|
||||
static async createConversation(newConversation: Conversation) {
|
||||
return await collections.conversations?.insertOne(newConversation);
|
||||
}
|
||||
|
||||
static async getAllConversationsForUser(userId: string) {
|
||||
const query = { 'members._id': new ObjectId(userId) };
|
||||
|
||||
const res = await collections.conversations?.find(query).toArray();
|
||||
|
||||
// exists
|
||||
if (res?.length) {
|
||||
return res as Conversation[];
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user