actions.js 818 B

12345678910111213141516171819202122232425262728293031323334353637
  1. Actions = new Mongo.Collection('actions');
  2. Actions.allow({
  3. insert(userId, doc) {
  4. return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  5. },
  6. update(userId, doc) {
  7. return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  8. },
  9. remove(userId, doc) {
  10. return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  11. },
  12. });
  13. Actions.before.insert((userId, doc) => {
  14. doc.createdAt = new Date();
  15. doc.modifiedAt = doc.createdAt;
  16. });
  17. Actions.before.update((userId, doc, fieldNames, modifier) => {
  18. modifier.$set = modifier.$set || {};
  19. modifier.$set.modifiedAt = new Date();
  20. });
  21. Actions.helpers({
  22. description() {
  23. return this.desc;
  24. },
  25. });
  26. if (Meteor.isServer) {
  27. Meteor.startup(() => {
  28. Actions._collection._ensureIndex({ modifiedAt: -1 });
  29. });
  30. }
  31. export default Actions;