Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 4.15: Add 'addMessage()' method to api
- Loading branch information
1 parent
f862793
commit 944316d
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
} | ||
} | ||
}); | ||
} |