Continued implementing sharing

This commit is contained in:
Thaum Rystra
2020-05-12 12:27:24 +02:00
parent dd213feb0a
commit 47206ccfc4
9 changed files with 465 additions and 83 deletions

View File

@@ -66,6 +66,16 @@ const userSchema = new SimpleSchema({
},
'subscribedLibraries.$': {
type: String,
regEx: SimpleSchema.RegEx.Id,
},
subscribedCharacters: {
type: Array,
defaultValue: [],
max: 100,
},
'subscribedCharacters.$': {
type: String,
regEx: SimpleSchema.RegEx.Id,
},
});
@@ -151,6 +161,31 @@ Meteor.users.setUsername = new ValidatedMethod({
}
});
Meteor.users.subscribeToLibrary = new ValidatedMethod({
name: 'Users.methods.subscribeToLibrary',
validate: new SimpleSchema({
libraryId:{
type: String,
regEx: SimpleSchema.RegEx.Id,
},
subscribe: {
type: Boolean,
},
}).validator(),
run({libraryId, subscribe}){
if (!this.userId) throw 'Can only subscribe if logged in';
if (subscribe){
return Meteor.users.update(this.userId, {
$addToSet: {subscribedLibraries: libraryId},
});
} else {
return Meteor.users.update(this.userId, {
$pullAll: {subscribedLibraries: libraryId},
});
}
}
});
Meteor.users.findUserByUsernameOrEmail = new ValidatedMethod({
name: 'Users.methods.findUserByUsernameOrEmail',
validate: new SimpleSchema({