Created
January 18, 2016 17:00
-
-
Save sjehutch/2f23ff8c5c3660f51dc7 to your computer and use it in GitHub Desktop.
Parse cloud code get average of SUM Rating
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.define("getrating", function(request, response) { | |
//Query class appointments | |
var query = new Parse.Query("appointments"); | |
//Query column trainer in appointments pass trainerid object | |
query.equalTo("trainer", request.params.trainerid); | |
query.find({ | |
success: function(results) { | |
var sum = 0; | |
for (var i = 0; i < results.length; ++i) { | |
//Get the sum of the field rate for the trainer | |
sum += results[i].get("rate"); | |
} | |
response.success(sum / results.length); | |
}, | |
error: function() { | |
response.error("Calculating ratings failed"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment