mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 04:26:41 -04:00
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
import Newsletter from "../namespace.js";
|
|
import MailChimpList from "./mailchimp/mailchimp_list.js";
|
|
import Users from 'meteor/nova:users';
|
|
|
|
Meteor.methods({
|
|
'newsletter.send': function () {
|
|
if(Users.isAdminById(this.userId))
|
|
return Newsletter.scheduleNextWithMailChimp(false);
|
|
},
|
|
'newsletter.test': function () {
|
|
if(Users.isAdminById(this.userId))
|
|
return Newsletter.scheduleNextWithMailChimp(true);
|
|
},
|
|
'newsletter.addUser'(user){
|
|
const currentUser = this.userId && Users.findOne(this.userId);
|
|
if (!user || !Users.canEdit(currentUser, user)) {
|
|
throw new Meteor.Error(601, 'sorry_you_cannot_edit_this_user');
|
|
}
|
|
|
|
try {
|
|
return MailChimpList.add(user, false);
|
|
} catch (error) {
|
|
throw new Meteor.Error(500, error.message);
|
|
}
|
|
},
|
|
'newsletter.removeUser'(user) {
|
|
const currentUser = this.userId && Users.findOne(this.userId);
|
|
if (!user || !Users.canEdit(currentUser, user)) {
|
|
throw new Meteor.Error(601, 'sorry_you_cannot_edit_this_user');
|
|
}
|
|
|
|
try {
|
|
return MailChimpList.remove(user);
|
|
} catch (error) {
|
|
throw new Meteor.Error(500, error.message);
|
|
}
|
|
},
|
|
'newsletter.addEmail'(email) {
|
|
try {
|
|
return MailChimpList.add(email, true);
|
|
} catch (error) {
|
|
throw new Meteor.Error(500, error.message);
|
|
}
|
|
}
|
|
});
|