diff --git a/api/server/methods.ts b/api/server/methods.ts index 530042ece..d754969ae 100644 --- a/api/server/methods.ts +++ b/api/server/methods.ts @@ -32,6 +32,20 @@ export function initMethods() { Chats.insert(chat); }, + removeChat(chatId: string): void { + if (!this.userId) throw new Meteor.Error('unauthorized', + 'User must be logged-in to remove chat'); + + check(chatId, nonEmptyString); + + const chatExists = !!Chats.collection.find(chatId).count(); + + if (!chatExists) throw new Meteor.Error('chat-not-exists', + 'Chat doesn\'t exist'); + + Messages.remove({chatId}); + Chats.remove(chatId); + }, updateProfile(profile: Profile): void { if (!this.userId) throw new Meteor.Error('unauthorized', 'User must be logged-in to create a new chat');