Permalink
Browse files

Step 6.17: Use check to add validations

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent 9ae9d91 commit 750225fe1828ff47ca2cbc95cd38d919f4698457
Showing with 10 additions and 0 deletions.
  1. +10 −0 api/server/methods.ts
View
@@ -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) {

0 comments on commit 750225f

Please sign in to comment.