Skip to content

Commit

Permalink
Step 7.27: Added updateProfile method
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB committed Feb 13, 2017
1 parent 06c504a commit b4a3d44
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion server/methods.ts
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { Chats, Messages } from '../imports/collections';
import { MessageType } from '../imports/models';
import { MessageType, Profile } from '../imports/models';
import { check, Match } from 'meteor/check';

const nonEmptyString = Match.Where((str) => {
Expand All @@ -9,6 +9,19 @@ 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);
Expand Down

0 comments on commit b4a3d44

Please sign in to comment.