Skip to content

Commit

Permalink
Step 9.2: Add removeChat method
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB committed Feb 13, 2017
1 parent f899b8c commit c432979
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server/methods.ts
Expand Up @@ -38,6 +38,24 @@ 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');
}

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 c432979

Please sign in to comment.