Skip to content

Commit 682653e

Browse files
dotansimhadarkbasic
authored andcommitted
Step 6.17: Use check to add validations
1 parent 6630710 commit 682653e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

api/server/methods.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import { Chats } from './collections/chats';
22
import { Messages } from './collections/messages';
33
import { MessageType } from './models';
4+
import { check, Match } from 'meteor/check';
5+
6+
const nonEmptyString = Match.Where((str) => {
7+
check(str, String);
8+
return str.length > 0;
9+
});
410

511
Meteor.methods({
612
addMessage(type: MessageType, chatId: string, content: string) {
13+
check(type, Match.OneOf(String, [ MessageType.TEXT ]));
14+
check(chatId, nonEmptyString);
15+
check(content, nonEmptyString);
16+
717
const chatExists = !!Chats.collection.find(chatId).count();
818

919
if (!chatExists) {

0 commit comments

Comments
 (0)