I was hoping to add an after save trigger to Parse.com that notified me when a certain type of user's account was updated. In this case, if column "user_ispro" is true in Parse.User I want to be emailed after the save (this column is either null to true). I added the code below but I am getting emailed on every update instead of just my query. Thoughts?
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");
}
});
});