I am trying to write cloud code on parse.com for the following. I have three classes User, Brand and Campaign. I keep LastLoginTime in the User class. Brand class has a relation named Campaigns to Campaign class. I need to retrieve LastLoginTime from user then get all the campaigns that have updatedAt date greater than LastLoginTime and finally I need to retrieve Brands related to these campaigns. Thus far I have been only able to make a function to get LastLoginTime. I have tried to use matchesKeyInQuery or chained functions but havent been able to solve. here is the code thus far.
Parse.Cloud.define("getLoginTime",function(request, response){
var User = Parse.Object.extend("User");
var query = new Parse.Query(User);
var lastlogin;
query.equalTo("objectId", request.params.objectId);
query.first({
success: function(object) {
// The object was retrieved successfully.
lastlogin = object.get("LastLoginTime");
response.success(lastlogin); // works well if left alone :)
console.log("entered time");
console.log(lastlogin);
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
}
});
});
The Above works, the below does not:
Parse.Cloud.define("getNewCampaigns", function (request, response){
var Campaign = Parse.Object.extend("Campaigns");
var cquery = new Parse.Query(Campaign);
var lastlogin;
lastlogin = parse.Cloud.run("getloginTime",request.params.objectId);
cquery.greaterThan("updatedAt",lastlogin);
cquery.find({
success: function(results) {
// results is an array of Parse.Object.
response.success(results);
},
error: function(error) {
// error is an instance of Parse.Error.
}
});
});
Is there a way or do I need to change my model.