posts.js 698 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @file
  3. *
  4. *
  5. * User: marand
  6. * Date: 30/08/15
  7. * Time: 10:48
  8. */
  9. // Not a "var", to make it global.
  10. Posts = new Mongo.Collection('posts');
  11. // Removed Posts.allow : we no longer trigger inserts from client.
  12. // This is in lib/ instead of server/ for latency compensation (?).
  13. Meteor.methods({
  14. postInsert: function(postAttributes) {
  15. check(Meteor.userId(), String);
  16. check(postAttributes, {
  17. title: String,
  18. url: String
  19. });
  20. var user = Meteor.user();
  21. var post = _.extend(postAttributes, {
  22. userId: user._id,
  23. author: user.username,
  24. submitted: new Date()
  25. });
  26. var postId = Posts.insert(post);
  27. return {
  28. _id: postId
  29. };
  30. }
  31. });