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) {