watch.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. Meteor.methods({
  3. watch(watchableType, id, level) {
  4. check(watchableType, String);
  5. check(id, String);
  6. check(level, Match.OneOf(String, null));
  7. const userId = Meteor.userId();
  8. let watchableObj = null;
  9. let board = null;
  10. if (watchableType === 'board') {
  11. watchableObj = ReactiveCache.getBoard(id);
  12. if (!watchableObj) throw new Meteor.Error('error-board-doesNotExist');
  13. board = watchableObj;
  14. } else if (watchableType === 'list') {
  15. watchableObj = ReactiveCache.getList(id);
  16. if (!watchableObj) throw new Meteor.Error('error-list-doesNotExist');
  17. board = watchableObj.board();
  18. } else if (watchableType === 'card') {
  19. watchableObj = ReactiveCache.getCard(id);
  20. if (!watchableObj) throw new Meteor.Error('error-card-doesNotExist');
  21. board = watchableObj.board();
  22. } else {
  23. throw new Meteor.Error('error-json-schema');
  24. }
  25. if (board.permission === 'private' && !board.hasMember(userId))
  26. throw new Meteor.Error('error-board-notAMember');
  27. watchableObj.setWatcher(userId, level);
  28. return true;
  29. },
  30. });