Refactored tabletop methods
This commit is contained in:
34
app/imports/api/tabletop/methods/insertTabletop.js
Normal file
34
app/imports/api/tabletop/methods/insertTabletop.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import Tabletops from '../Tabletops.js';
|
||||
import { assertAdmin } from '/imports/api/sharing/sharingPermissions.js';
|
||||
import { assertUserHasPaidBenefits } from '/imports/api/users/patreon/tiers.js';
|
||||
|
||||
const insertTabletop = new ValidatedMethod({
|
||||
|
||||
name: 'tabletops.insert',
|
||||
|
||||
validate: null,
|
||||
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
|
||||
run() {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('tabletops.insert.denied',
|
||||
'You need to be logged in to insert a tabletop');
|
||||
}
|
||||
assertUserHasPaidBenefits(this.userId);
|
||||
assertAdmin(this.userId);
|
||||
|
||||
return Tabletops.insert({
|
||||
gameMaster: this.userId,
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
export default insertTabletop;
|
||||
Reference in New Issue
Block a user