From 4bd57c4b43d9cbe0ae5b9b45c1307af4624b31c9 Mon Sep 17 00:00:00 2001 From: dotansimha Date: Tue, 24 Jan 2017 15:14:19 +0200 Subject: [PATCH] Step 6.17: Use check to add validations --- api/server/methods.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/server/methods.ts b/api/server/methods.ts index ce7c3d444..02f8466ad 100644 --- a/api/server/methods.ts +++ b/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) {