Added the setting to swap ability scores and modifiers to the account page

This commit is contained in:
Stefan Zermatten
2020-06-22 13:22:53 +02:00
parent c4dc5895aa
commit 8cbfec25b3
4 changed files with 82 additions and 7 deletions

View File

@@ -83,6 +83,15 @@ const userSchema = new SimpleSchema({
blackbox: true,
optional: true,
},
preferences: {
type: Object,
optional: true,
defaultValue: {},
},
'preferences.swapAbilityScoresAndModifiers': {
type: Boolean,
optional: true,
},
});
Meteor.users.attachSchema(userSchema);
@@ -192,6 +201,36 @@ Meteor.users.setUsername = new ValidatedMethod({
}
});
Meteor.users.setPreference = new ValidatedMethod({
name: 'users.setPreference',
validate: new SimpleSchema({
preference:{
type: String,
},
value: {
type: SimpleSchema.oneOf(Boolean),
},
}).validator(),
mixins: [RateLimiterMixin],
rateLimit: {
numRequests: 5,
timeInterval: 5000,
},
run({preference, value}){
if (!this.userId) throw 'You can only set preferences once logged in';
let prefPath = `preferences.${preference}`
if (value == true){
return Meteor.users.update(this.userId, {
$set: {[prefPath]: true},
});
} else {
return Meteor.users.update(this.userId, {
$unset: {[prefPath]: 1},
});
}
},
});
Meteor.users.subscribeToLibrary = new ValidatedMethod({
name: 'users.subscribeToLibrary',
validate: new SimpleSchema({