Skip to content

Commit

Permalink
Step 4.16: Add 'addMessage()' method to api
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Nov 27, 2016
1 parent 0bed0c4 commit 63079e8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server/imports/methods/methods.ts
@@ -0,0 +1,18 @@
import {Meteor} from 'meteor/meteor';
import {Chats} from "../../../both/collections/chats.collection";
import {Messages} from "../../../both/collections/messages.collection";

Meteor.methods({
addMessage(chatId: string, content: string): void {
const chatExists = !!Chats.collection.find(chatId).count();

if (!chatExists) throw new Meteor.Error('chat-not-exists',
'Chat doesn\'t exist');

Messages.collection.insert({
chatId: chatId,
content: content,
createdAt: new Date()
});
}
});

0 comments on commit 63079e8

Please sign in to comment.