actions.js 858 B

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