【发布时间】:2014-11-23 23:33:27
【问题描述】:
我希望向 Parse.com 添加一个保存后触发器,当某种类型的用户帐户更新时通知我。在这种情况下,如果 Parse.User 中的“user_ispro”列为真,我希望在保存后通过电子邮件发送(此列要么为空,要么为真)。我在下面添加了代码,但每次更新都会收到电子邮件,而不仅仅是我的查询。想法?
Parse.Cloud.afterSave(Parse.User, function(request) {
var Mandrill = require('mandrill');
query = new Parse.Query(Parse.User);
query.equalTo("user_ispro", true);
query.find({
success: function(results) {
Mandrill.initialize('xxxx');
Mandrill.sendEmail({
message: {
text: "Email Text",
subject: "Subject",
from_email: "test@test.com",
from_name: "Test",
to: [{
email: "test@test.com",
name: "Test"
}]
},
async: true
}, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
},
error: function() {
response.error("User is not Pro");
}
});
});
【问题讨论】:
标签: javascript parse-platform mandrill parse-cloud-code