Refactored tabletop methods

This commit is contained in:
Stefan Zermatten
2021-10-10 19:58:41 +02:00
parent 51d3fbbcb7
commit eebfbfd636
7 changed files with 165 additions and 185 deletions

View File

@@ -0,0 +1,25 @@
import Tabletops from '../../Tabletops.js';
export function assertUserInTabletop(tabletopId, userId){
let tabletop = Tabletops.findOne(tabletopId);
if (!tabletop){
throw new Meteor.Error('Tabletop does not exist',
'No tabletop could be found for the given tabletop id');
}
if (tabletop.gameMaster !== userId && !tabletop.players.includes(userId)){
throw new Meteor.Error('Not in tabletop',
'The user is not the gamemaster or a player in the given tabletop');
}
}
export function assertUserIsTabletopOwner(tabletopId, userId){
let tabletop = Tabletops.findOne(tabletopId);
if (!tabletop){
throw new Meteor.Error('Tabletop does not exist',
'No tabletop could be found for the given tabletop id');
}
if (tabletop.gameMaster !== userId){
throw new Meteor.Error('Not the owner',
'The user is not the owner of the given tabletop');
}
}