Skip to content

Commit

Permalink
Step 4.19: Add validations to 'addMessage()' method in api
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Nov 27, 2016
1 parent 60c8fc6 commit a4f1233
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 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',
Expand Down

0 comments on commit a4f1233

Please sign in to comment.