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
kamilkisiela authored and DAB0mB committed Dec 17, 2016
1 parent 65f4f2d commit d93d12d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/imports/methods/methods.ts
Expand Up @@ -45,6 +45,20 @@ Meteor.methods({

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);
},
addMessage(chatId: string, content: string): 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 d93d12d

Please sign in to comment.