Skip to content

Commit

Permalink
Step 6.15: Implement Meteor method for adding a new message
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Mar 23, 2017
1 parent 96695bb commit 9a63930
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions api/server/methods.ts
@@ -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 9a63930

Please sign in to comment.