Skip to content

Commit

Permalink
Step 6.8: Add new chat method to api
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Dotan Simha committed Nov 22, 2016
1 parent f95b155 commit 16e8427
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions api/server/methods.js
Expand Up @@ -36,5 +36,29 @@ Meteor.methods({
}

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

newChat(otherId) {
if (!this.userId) {
throw new Meteor.Error('not-logged-in',
'Must be logged to create a chat.');
}

check(otherId, String);
const otherUser = Meteor.users.findOne(otherId);

if (!otherUser) {
throw new Meteor.Error('user-not-exists',
'Chat\'s user not exists');
}

const chat = {
userIds: [this.userId, otherId],
createdAt: new Date()
};

const chatId = Chats.insert(chat);

return chatId;
}
});

0 comments on commit 16e8427

Please sign in to comment.