Permalink
Browse files

Step 6.15: Implement Meteor method for adding a new message

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent 561b979 commit c72329658f21c83bcd206bd0236ba5c5f7ef78c5
Showing with 23 additions and 0 deletions.
  1. +23 −0 api/server/methods.ts
View
@@ -0,0 +1,23 @@
import { Chats } from './collections/chats';
import { Messages } from './collections/messages';
import { MessageType } from './models';
Meteor.methods({
addMessage(type: MessageType, chatId: string, content: string) {
const chatExists = !!Chats.collection.find(chatId).count();
if (!chatExists) {
throw new Meteor.Error('chat-not-exists',
'Chat doesn\'t exist');
}
return {
messageId: Messages.collection.insert({
chatId: chatId,
content: content,
createdAt: new Date(),
type: type
})
};
}
});

0 comments on commit c723296

Please sign in to comment.