diff --git a/api/server/methods.ts b/api/server/methods.ts new file mode 100644 index 000000000..2c103f00f --- /dev/null +++ b/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() + }) + } + } + }); +}