We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 561b979 commit c723296Copy full SHA for c723296
api/server/methods.ts
@@ -0,0 +1,23 @@
1
+import { Chats } from './collections/chats';
2
+import { Messages } from './collections/messages';
3
+import { MessageType } from './models';
4
+
5
+Meteor.methods({
6
+ addMessage(type: MessageType, chatId: string, content: string) {
7
+ const chatExists = !!Chats.collection.find(chatId).count();
8
9
+ if (!chatExists) {
10
+ throw new Meteor.Error('chat-not-exists',
11
+ 'Chat doesn\'t exist');
12
+ }
13
14
+ return {
15
+ messageId: Messages.collection.insert({
16
+ chatId: chatId,
17
+ content: content,
18
+ createdAt: new Date(),
19
+ type: type
20
+ })
21
+ };
22
23
+});
0 commit comments