2012-10-04 11:45:12 +10:00
|
|
|
Meteor.methods({
|
|
|
|
post: function(post){
|
2012-10-04 11:53:15 +10:00
|
|
|
var user = Meteor.user();
|
|
|
|
if (!user || !user.approved)
|
|
|
|
throw new Meteor.Error('You need to login and be approved to post new stories.')
|
|
|
|
|
2012-10-04 11:45:12 +10:00
|
|
|
post = _.extend(post, {
|
2012-10-04 11:53:15 +10:00
|
|
|
userId: user._id,
|
|
|
|
author: user.username,
|
2012-10-04 11:45:12 +10:00
|
|
|
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;
|
2012-10-04 11:45:12 +10:00
|
|
|
}
|
|
|
|
});
|