diff --git a/server/imports/methods/methods.ts b/server/imports/methods/methods.ts index 0fce545..89c378b 100644 --- a/server/imports/methods/methods.ts +++ b/server/imports/methods/methods.ts @@ -1,9 +1,18 @@ import {Meteor} from 'meteor/meteor'; import {Chats} from "../../../both/collections/chats.collection"; import {Messages} from "../../../both/collections/messages.collection"; +import {check, Match} from 'meteor/check'; + +const nonEmptyString = Match.Where((str) => { + check(str, String); + return str.length > 0; +}); Meteor.methods({ addMessage(chatId: string, content: string): void { + check(chatId, nonEmptyString); + check(content, nonEmptyString); + const chatExists = !!Chats.collection.find(chatId).count(); if (!chatExists) throw new Meteor.Error('chat-not-exists',