MichaelAngelo
MichaelAngelo

Reputation: 375

parse.com cloud code problems but in javascript works perfect

I spilled 8 hours on this piece of code that just does not want to work

On localhost and javascript it works great, but in the parse.com cloud code i get undefined for a variable.

Parse.Cloud.define("goGetPrices", function(request, response) {

var price;

function getPrices(stockPrice){
console.log(stockPrice);

var PriceTick = Parse.Object.extend("StockPrices");
var queryInstal = new Parse.Query(Parse.Installation);

var queryLess = new Parse.Query(PriceTick);
var queryMore = new Parse.Query(PriceTick);

queryLess.equalTo("Position","Less");
queryLess.greaterThan("Price", stockPrice);

console.log(PriceTick) // RETURNS UNDEFINED
console.log(queryInstal) // RETURNS UNDEFINED

Because those return undefined the rest of the code can't work...the weird thing is this works great on my localhost without cloud code

queryLess.find({
success: function(results) {
//Less than

console.log("found less");

 if (results.length) {

for (var i = 0; i < results.length; i++) { 
var object = results[i]

var devicetoken = object.get('devicetoken');
var objID = object.get('objectId');

console.log("Got Less");
queryInstal.equalTo('deviceToken', devicetoken);
queryInstal.equalTo('deviceType', 'ios');

Parse.Push.send({
  where: queryInstal, // Set our Installation query
  data: {
    alert: "The price is now: "+stockPrice
  }
}, {
  success: function() {
    // Push was successful
          object.destroy({});


  },
  error: function(error) {
    // Handle error
  }
});
}
}},
 error: function(error) {
  alert("Error: " + error.code + " " + error.message);
 }
});




Parse.Cloud.httpRequest({
url: "example.php",
dataType: 'json',
type: 'GET',
success: function(data) {
 price = data.data.Response.price;
 response.success("yes")
 getPrices(price);

},
error: function(data) {
  response.error('Request failed with response code ' + data.status);

}
}); });

Upvotes: 1

Views: 551

Answers (1)

Dmitri Zaitsev
Dmitri Zaitsev

Reputation: 14066

You have to use Parse.Query(ClassName), where ClassName is a name string or instance of Parse.Object subclass:

https://parse.com/docs/js/symbols/Parse.Query.html

Upvotes: 2

Related Questions