Skip to content

Commit

Permalink
Step 5.17: Add 'updateProfile' method
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored and DAB0mB committed Dec 16, 2016
1 parent 637f4b8 commit 2a7ee2d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/imports/methods/methods.ts
Expand Up @@ -2,13 +2,27 @@ import {Meteor} from 'meteor/meteor';
import {Chats} from "../../../both/collections/chats.collection";
import {Messages} from "../../../both/collections/messages.collection";
import {check, Match} from 'meteor/check';
import {Profile} from '../../../both/models/profile.model';

const nonEmptyString = Match.Where((str) => {
check(str, String);
return str.length > 0;
});

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,
picture: nonEmptyString
});

Meteor.users.update(this.userId, {
$set: {profile}
});
},
addMessage(chatId: string, content: string): void {
check(chatId, nonEmptyString);
check(content, nonEmptyString);
Expand Down

0 comments on commit 2a7ee2d

Please sign in to comment.