Skip to content

Commit

Permalink
Step 6.17: Use check to add validations
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Mar 23, 2017
1 parent eaf8a8b commit 4bd57c4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/server/methods.ts
@@ -1,9 +1,19 @@
import { Chats } from './collections/chats';
import { Messages } from './collections/messages';
import { MessageType } from './models';
import { check, Match } from 'meteor/check';

const nonEmptyString = Match.Where((str) => {
check(str, String);
return str.length > 0;
});

Meteor.methods({
addMessage(type: MessageType, chatId: string, content: string) {
check(type, Match.OneOf(String, [ MessageType.TEXT ]));
check(chatId, nonEmptyString);
check(content, nonEmptyString);

const chatExists = !!Chats.collection.find(chatId).count();

if (!chatExists) {
Expand Down

0 comments on commit 4bd57c4

Please sign in to comment.