watch.js 1.1 KB

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