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 darkbasic committed Oct 16, 2017
1 parent 6630710 commit 682653e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/server/methods.ts
Original file line number Diff line number Diff line change
@@ -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 682653e

Please sign in to comment.