Last active
May 25, 2016 11:55
-
-
Save Bashta/f2d5d6c4e68012186fb4c226d6842167 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parse.Cloud.job("incomingEventNotification", function () { | |
Parse.Cloud.useMasterKey(); | |
var query = new Parse.Query("Event"); | |
query.greaterThan("limit", 1); | |
query.equalTo("notifiedAboutUpcomingEvent", false); | |
query.find().then(function(results) { | |
//get the event | |
for (var event in results) { | |
for (var userID in event.object.get("attendeeIDs")) { | |
var pushQuery = new Parse.Query(Parse.Installation); | |
pushQuery.equalTo('channels', userID); | |
var eventName = event.object.get("summary"); | |
Parse.Push.send({ | |
where: pushQuery, | |
data: { | |
alert: eventName + ", " + "starting in 24 hours" | |
}, | |
}, { | |
success: function (success) { | |
// Push was successful | |
event.set("notifiedAboutUpcomingEvent", true) | |
event.save() | |
}, | |
error: function (error) { | |
throw "Got an error " + error.code + " : " + error.message; | |
} | |
} | |
} | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment