Created
January 29, 2018 16:23
-
-
Save gngeorgiev/aa34c11ad8d8cf6460c4b67d5b36b608 to your computer and use it in GitHub Desktop.
Parse Installation deduplication - Cloud Code
This file contains 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.beforeSave(Parse.Installation, function(request, response) { | |
var androidId = request.object.get("androidId"); | |
if (!androidId) { | |
console.warn("No androidId found, save and exit"); | |
return response.success(); | |
} | |
var query = new Parse.Query(Parse.Installation); | |
query.equalTo("androidId", androidId); | |
query.ascending("createdAt"); | |
query.find() | |
.then(results => { | |
return results.map(r => r.destroy()); | |
}) | |
.then(() => response.success()) | |
.catch(err => response.error("Error: Can't query for Installation objects.")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment