Vulcan/packages/nova-newsletter/lib/server/methods.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-03-18 11:53:46 +09:00
import Campaign from "./campaign.js";
import MailChimpList from "./mailchimp.js";
Meteor.methods({
sendCampaign: function () {
if(Users.is.adminById(this.userId))
return Campaign.scheduleNextWithMailChimp(false);
},
testCampaign: function () {
if(Users.is.adminById(this.userId))
return Campaign.scheduleNextWithMailChimp(true);
},
2016-05-26 10:46:30 +02:00
'newsletter.addUser'(user){
if (!user || !Users.can.editById(this.userId, user)) {
throw new Meteor.Error(601, __('sorry_you_cannot_edit_this_user'));
}
2016-03-18 11:53:46 +09:00
try {
return MailChimpList.add(user, false);
2016-03-18 11:53:46 +09:00
} catch (error) {
throw new Meteor.Error(500, error.message);
}
},
2016-05-26 10:46:30 +02:00
'newsletter.removeUser'(user) {
if (!user || !Users.can.editById(this.userId, user)) {
throw new Meteor.Error(601, __('sorry_you_cannot_edit_this_user'));
}
2016-05-23 09:07:13 +02:00
try {
return MailChimpList.remove(user);
2016-05-23 09:07:13 +02:00
} catch (error) {
throw new Meteor.Error(500, error.message);
}
},
2016-05-26 10:46:30 +02:00
'newsletter.addEmail'(email) {
try {
return MailChimpList.add(email, true);
} catch (error) {
throw new Meteor.Error(500, error.message);
2016-03-18 11:53:46 +09:00
}
}
});