Skip to content

Commit

Permalink
renames model to Comment
Browse files Browse the repository at this point in the history
Now that we’re not using Comment, we can rename this (Comment is
used in the browser).
  • Loading branch information
AdamBrodzinski committed Jul 19, 2015
1 parent 0cd4589 commit fd8b915
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions both/models/comment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*global Mongo, PostComment:true, PostComments:true, Post, User */
// Comment is a global function so we can't use it, hence PostComment
/*global Mongo, Comment:true, Comments:true, Post, User */

// NOTE, doing meteor data/collections this way loses much of Meteor's
// 'magic' and makes more work for us but i'm totally ok trading convenience
Expand All @@ -19,17 +18,17 @@ var schema = {
username: String,
};

PostComments = new Mongo.Collection('postComments');
Comments = new Mongo.Collection('postComments');

// increment comment count on new comment
PostComments.after.insert(function (userId, doc) {
Comments.after.insert(function (userId, doc) {
Post.increment(doc.postId, 'commentCount');
});


// ** Security README **
//
// all PostComment crud MiniMongo methods are disabled on the client
// all Comment crud MiniMongo methods are disabled on the client
// by not having allow/deny rules. This ensures more granular security & moves
// the security logic into the meteor method. all mutation has to happen with
// the Meteor methods. These methods are placed into the 'both' folder so that
Expand All @@ -40,12 +39,12 @@ PostComments.after.insert(function (userId, doc) {

Meteor.methods({
/**
* Creates a PostComment document
* Creates a Comment document
* @method
* @param {object} data - data to insert
* @returns {string} of document id
*/
"PostComment.create": function(data) {
"Comment.create": function(data) {
var docId;
if (User.loggedOut()) throw new Meteor.Error(401, "Login required");

Expand All @@ -55,21 +54,21 @@ Meteor.methods({
// Schema check, throws if it doesn't match
check(data, schema);

docId = PostComments.insert(data);
docId = Comments.insert(data);

console.log("[PostComment.create]", docId);
console.log("[Comment.create]", docId);
return docId;
},


/**
* Updates a PostComment document using $set
* Updates a Comment document using $set
* @method
* @param {string} docId - The doc id to update
* @param {object} data - data to update
* @returns {number} of documents updated (0|1)
*/
"PostComment.update": function(docId, data) {
"Comment.update": function(docId, data) {
var optional = Match.Optional;
var count, selector;

Expand All @@ -81,29 +80,28 @@ Meteor.methods({
// if caller doesn't own doc, update will fail because fields won't match
selector = {_id: docId, ownerId: User.id()};

count = PostComments.update(selector, {$set: data});
count = Comments.update(selector, {$set: data});

console.log("[PostComment.update]", count, docId);
console.log("[Comment.update]", count, docId);
return count;
},


/**
* Destroys a PostComment
* Destroys a Comment
* @method
* @param {string} docId - The doc id to destroy
* @returns {number} of documents destroyed (0|1)
*/
"PostComment.destroy": function(docId) {
"Comment.destroy": function(docId) {
check(docId, String);

if (User.loggedOut()) throw new Meteor.Error(401, "Login required");

// if caller doesn't own doc, destroy will fail because fields won't match
var count = PostComments.remove({_id: docId, ownerId: User.id()});
var count = Comments.remove({_id: docId, ownerId: User.id()});

console.log("[PostComment.destroy]", count);
console.log("[Comment.destroy]", count);
return count;
}
});

0 comments on commit fd8b915

Please sign in to comment.