I have two working Cloud Code functions: the first queries Parse.User and returns the objectId of record matching the username, the second queries Parse.Installation and looks returns the the objectId and deviceType of the record matching the pointer column to "user"(holds the users objectId).
In the interest of not having to continually make new HTTP calls in a VBA application I am trying put combined these two functions into one. I have written
Parse.Cloud.define ("lookupUser", function(request, response){
var email = request.params.email;
if(!email) {
response.error("Missing parameter: email");
return ;
}
Parse.Cloud.useMasterKey();
var objectId;
var installations = [];
var InstallationQuery = new Parse.Query(Parse.Installation);
var UserQuery = new Parse.Query(Parse.User);
UserQuery.equalTo("username", email);
UserQuery.first({
success: function(user){
objectId = user.id;
InstallationQuery.equalTo("user", objectId);
InstallationQuery.find({
success: function(results){
for(var i = 0; i < results.length; i++){
var object = result[i];
installations.push({
objectId: object.id,
deviceType: object.get("deviceType")
});
}
}
}),
response.success(objectId + installations);
}
});
});
This successfully passes the objectId, unfortunately installations does not show up in the result and looks like this
{
"result":"b194RP5n89"
}
When I remove objectId from the response.succes like this
response.success(installations);
my result looks like this
{
"result":[
]
}
I'm sure this is an issue with Async, but I'm operating outside of my depth.
Any help is deeply appreciated.