actions.js 938 B

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