2023-01-14 13:29:57 +01:00
|
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
|
|
|
|
2016-01-05 23:26:02 +08:00
|
|
|
Meteor.methods({
|
|
|
|
|
watch(watchableType, id, level) {
|
|
|
|
|
check(watchableType, String);
|
|
|
|
|
check(id, String);
|
|
|
|
|
check(level, Match.OneOf(String, null));
|
|
|
|
|
|
|
|
|
|
const userId = Meteor.userId();
|
|
|
|
|
|
|
|
|
|
let watchableObj = null;
|
|
|
|
|
let board = null;
|
|
|
|
|
if (watchableType === 'board') {
|
2023-01-14 13:29:57 +01:00
|
|
|
watchableObj = ReactiveCache.getBoard(id);
|
2016-01-05 23:26:02 +08:00
|
|
|
if (!watchableObj) throw new Meteor.Error('error-board-doesNotExist');
|
|
|
|
|
board = watchableObj;
|
|
|
|
|
} else if (watchableType === 'list') {
|
2023-01-14 19:33:36 +01:00
|
|
|
watchableObj = ReactiveCache.getList(id);
|
2016-01-05 23:26:02 +08:00
|
|
|
if (!watchableObj) throw new Meteor.Error('error-list-doesNotExist');
|
|
|
|
|
board = watchableObj.board();
|
|
|
|
|
} else if (watchableType === 'card') {
|
2022-12-16 16:36:47 +01:00
|
|
|
watchableObj = ReactiveCache.getCard(id);
|
2016-01-05 23:26:02 +08:00
|
|
|
if (!watchableObj) throw new Meteor.Error('error-card-doesNotExist');
|
|
|
|
|
board = watchableObj.board();
|
|
|
|
|
} else {
|
|
|
|
|
throw new Meteor.Error('error-json-schema');
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-28 12:52:09 -05:00
|
|
|
if (board.permission === 'private' && !board.hasMember(userId))
|
2016-01-05 23:26:02 +08:00
|
|
|
throw new Meteor.Error('error-board-notAMember');
|
|
|
|
|
|
|
|
|
|
watchableObj.setWatcher(userId, level);
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
});
|