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 darkbasic committed Oct 16, 2017
1 parent 8d50ffb commit 1b58035
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 1b58035

Please sign in to comment.