Permalink
Browse files

Step 7.28: Added updateProfile method

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 26, 2017
1 parent 7a28688 commit 8d50ffb1d8bdec45c324c5b57fa24fdf5005f00e
Showing with 13 additions and 1 deletion.
  1. +13 −1 api/server/methods.ts
@@ -1,6 +1,6 @@
import { Chats } from './collections/chats';
import { Messages } from './collections/messages';
import { MessageType } from './models';
import { MessageType, Profile } from './models';
import { check, Match } from 'meteor/check';
const nonEmptyString = Match.Where((str) => {
@@ -9,6 +9,18 @@ const nonEmptyString = Match.Where((str) => {
});
Meteor.methods({
updateProfile(profile: Profile): void {
if (!this.userId) throw new Meteor.Error('unauthorized',
'User must be logged-in to create a new chat');
check(profile, {
name: nonEmptyString
});
Meteor.users.update(this.userId, {
$set: {profile}
});
},
addMessage(type: MessageType, chatId: string, content: string) {
check(type, Match.OneOf(String, [ MessageType.TEXT ]));
check(chatId, nonEmptyString);

0 comments on commit 8d50ffb

Please sign in to comment.