Last active
December 14, 2015 13:08
-
-
Save jtubert/5091694 to your computer and use it in GitHub Desktop.
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.define("loadChannelsFromDate", function(request, response) { | |
var fromDate = request.params.fromDate; | |
var toDate = request.params.toDate; | |
var count = request.params.count; | |
var query = new Parse.Query("archupObject"); | |
query.limit = count; | |
if(fromDate){ | |
query.greaterThan("updatedAt", fromDate); | |
} | |
query.lessThan("updatedAt", toDate); | |
var channels = [{name:"New York",type:"location"},{name:"Apple",type:"keyword"}]; | |
var channelArr = []; | |
query.find({ | |
success: function(results) { | |
for (var j = 0; j < results.length; ++j) { | |
var update = results[j].get("update"); | |
var index; | |
for(var i=0;i<channels.length;i++){ | |
//initialize all objects | |
if(j == 0){ | |
channelArr[i] = {}; | |
channelArr[i].channelID = i; | |
channelArr[i].channelType = channels[i].type; | |
channelArr[i].name = channels[i].name; | |
channelArr[i].happyCount = 0; | |
channelArr[i].unhappyCount = 0; | |
channelArr[i].updatedDate = ""; | |
channelArr[i].latitude = Number(update.latitude); | |
channelArr[i].longitude = Number(update.longitude); | |
index = update.iphone_location_data.indexOf(channels[i].name); | |
} | |
if(index > -1){ | |
//if happy | |
if(update.status == "0"){ | |
channelArr[i].happyCount++; | |
}else{ | |
channelArr[i].unhappyCount++; | |
} | |
} | |
} | |
} | |
response.success(channelArr); | |
}, | |
error: function() { | |
response.error("response error from server"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment