From 21784f19d0d29c2d206c1699205e33d9bf872fd6 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Mon, 10 Oct 2016 13:09:34 +0200 Subject: [PATCH] Step 5.17: Add 'updateProfile' method --- server/imports/methods/methods.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/imports/methods/methods.ts b/server/imports/methods/methods.ts index 89c378b..3f6d2c2 100644 --- a/server/imports/methods/methods.ts +++ b/server/imports/methods/methods.ts @@ -2,6 +2,7 @@ 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); @@ -9,6 +10,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, + picture: nonEmptyString + }); + + Meteor.users.update(this.userId, { + $set: {profile} + }); + }, addMessage(chatId: string, content: string): void { check(chatId, nonEmptyString); check(content, nonEmptyString);