Vulcan/common/post.js

30 lines
661 B
JavaScript
Raw Normal View History

Meteor.methods({
post: function(post){
2012-10-04 11:53:15 +10:00
var user = Meteor.user();
2012-10-05 13:59:40 +09:00
if (!user || !canPost(user))
2012-10-10 08:32:49 +09:00
throw new Meteor.Error(123, 'You need to login or be invited to post new stories.');
2012-10-11 13:21:10 +09:00
if(!post.headline)
throw new Meteor.Error(456, 'Please fill in a headline');
2012-10-05 13:59:40 +09:00
if(!this.isSimulation)
limitRate(user, Posts, 30);
post = _.extend(post, {
2012-10-04 11:53:15 +10:00
userId: user._id,
author: getDisplayName(user),
submitted: new Date().getTime(),
votes: 0,
comments: 0,
baseScore: 0,
score: 0
});
2012-10-04 15:26:59 +09:00
var postId=Posts.insert(post);
Meteor.call('upvotePost', postId);
return postId;
}
});