Skip to content

Commit

Permalink
Step 4.15: Add 'addMessage()' method to api
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Dec 24, 2016
1 parent f862793 commit 944316d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api/server/methods.ts
@@ -0,0 +1,21 @@
import { Meteor } from 'meteor/meteor';
import {Chats, Messages} from "../collections/whatsapp-collections";

export function initMethods() {
Meteor.methods({
addMessage(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()
})
}
}
});
}

0 comments on commit 944316d

Please sign in to comment.