Skip to content

Commit

Permalink
Step 7.2: Define 'removeChat' Method
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Dec 24, 2016
1 parent 543fdc6 commit 51d7707
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions api/server/methods.ts
Expand Up @@ -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');
Expand Down

0 comments on commit 51d7707

Please sign in to comment.