Skip to content

Commit c723296

Browse files
dotansimhadarkbasic
authored andcommitted
Step 6.15: Implement Meteor method for adding a new message
1 parent 561b979 commit c723296

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

api/server/methods.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)