2016-06-23 17:24:58 +09:00
|
|
|
import Newsletter from "../namespace.js";
|
|
|
|
import MailChimpList from "./mailchimp/mailchimp_list.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({
|
2016-06-23 17:24:58 +09:00
|
|
|
'newsletter.send': function () {
|
2016-07-21 14:51:58 +09:00
|
|
|
if(Users.isAdminById(this.userId))
|
2016-06-23 17:24:58 +09:00
|
|
|
return Newsletter.scheduleNextWithMailChimp(false);
|
2016-03-18 11:53:46 +09:00
|
|
|
},
|
2016-06-23 17:24:58 +09:00
|
|
|
'newsletter.test': function () {
|
2016-07-21 14:51:58 +09:00
|
|
|
if(Users.isAdminById(this.userId))
|
2016-06-23 17:24:58 +09:00
|
|
|
return Newsletter.scheduleNextWithMailChimp(true);
|
2016-03-18 11:53:46 +09:00
|
|
|
},
|
2016-05-26 10:46:30 +02:00
|
|
|
'newsletter.addUser'(user){
|
2016-07-20 10:25:05 +09:00
|
|
|
const currentUser = this.userId && Users.findOne(this.userId);
|
|
|
|
if (!user || !Users.canEdit(currentUser, user)) {
|
2016-07-04 10:42:50 +09:00
|
|
|
throw new Meteor.Error(601, 'sorry_you_cannot_edit_this_user');
|
2016-05-25 08:52:04 +02:00
|
|
|
}
|
|
|
|
|
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-07-20 10:25:05 +09:00
|
|
|
const currentUser = this.userId && Users.findOne(this.userId);
|
|
|
|
if (!user || !Users.canEdit(currentUser, user)) {
|
2016-07-04 10:42:50 +09:00
|
|
|
throw new Meteor.Error(601, 'sorry_you_cannot_edit_this_user');
|
2016-05-25 08:52:04 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|