2016-03-18 11:53:46 +09:00
|
|
|
import Campaign from "./campaign.js";
|
|
|
|
import MailChimpList from "./mailchimp.js";
|
2016-06-23 15:00:58 +09:00
|
|
|
import Users from 'meteor/nova:users';
|
2016-03-18 11:53:46 +09:00
|
|
|
|
|
|
|
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){
|
2016-05-25 08:52:04 +02:00
|
|
|
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 {
|
2016-05-25 08:52:04 +02:00
|
|
|
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) {
|
2016-05-25 08:52:04 +02:00
|
|
|
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 {
|
2016-05-25 08:52:04 +02:00
|
|
|
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) {
|
2016-05-26 10:48:38 +02:00
|
|
|
try {
|
|
|
|
return MailChimpList.add(email, true);
|
|
|
|
} catch (error) {
|
|
|
|
throw new Meteor.Error(500, error.message);
|
2016-03-18 11:53:46 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|