Skip to content

Commit

Permalink
Step 4.20: Add update name method
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Dotan Simha committed Nov 23, 2016
1 parent 5268e77 commit c2ad61d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,19 @@ Meteor.methods({
Chats.update(message.chatId, { $set: { lastMessage: message } });

return messageId;
},
updateName(name) {
if (!this.userId) {
throw new Meteor.Error('not-logged-in',
'Must be logged in to update his name.');
}

check(name, String);

if (name.length === 0) {
throw Meteor.Error('name-required', 'Must provide a user name');
}

return Meteor.users.update(this.userId, { $set: { 'profile.name': name } });
}
});

0 comments on commit c2ad61d

Please sign in to comment.