Skip to content

Commit

Permalink
Step 7.29: Added restriction on new message method
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Feb 13, 2017
1 parent e1ef47c commit de9bb7d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/server/methods.ts
Expand Up @@ -22,6 +22,9 @@ Meteor.methods({
});
},
addMessage(type: MessageType, chatId: string, content: string) {
if (!this.userId) throw new Meteor.Error('unauthorized',
'User must be logged-in to create a new chat');

check(type, Match.OneOf(String, [ MessageType.TEXT ]));
check(chatId, nonEmptyString);
check(content, nonEmptyString);
Expand All @@ -36,6 +39,7 @@ Meteor.methods({
return {
messageId: Messages.collection.insert({
chatId: chatId,
senderId: this.userId,
content: content,
createdAt: new Date(),
type: type
Expand Down

0 comments on commit de9bb7d

Please sign in to comment.