In the backend controller, I have the following code snippet: 'use strict';
var Comment = require('../../../models/comment');
module.exports = {
description: 'Create a Comment',
notes: 'Create a comment',
tags:['comment'],
handler: function(request, reply){
console.log('COMMM PAY', request.payload);
Comment.create({
itemId: request.payload.itemId,
text: request.payload.commentText,
rating: request.payload.rating,
userId: request.auth.credentials._id
}, function(err, comment){
reply(comment);
});
}
};
This is what I have in the front-end controller:
$scope.createComment = function(comment, item, rating){
var body = {itemId:item.itemId,
commentText: comment.text,
rating: rating};
Comment.create(body).then(function(res){
toastr.success('Review Submitted.');
console.log('RESdfdas.data',res.data);
$scope.comments.push(res.data);
$scope.showCommentForm = !!!$scope.showCommentForm;
$scope.comment = {};
getComments();
});
};
I'm looking for a way to restrict users from giving multiple comments/ratings on the same item. I believe implementing an if/else conditional that checks for existing documents with matching userId and itemId would be necessary to return an error.
If needed, I can provide the HTML/Jade code as well.