1

I'm not sure what's going wrong here / how I can fix it.

Parse.Cloud.job("expireTimes", function(request, response) {
var currentTime = new Date().getTime() / 1000;
var Wait = Parse.Object.extend("Wait");
Parse.Object.registerSubclass("Wait", Wait);
var query = new Parse.Query(Wait);
query.select(["times", "timestamp"]);
query.find({
    success: function(results) {
        for (var i = 0; i < timestamps.length; i++) {
            if (currentTime >= timestamps[i] + 60) {
                // Delete old wait times
                timestamps.splice(i, 1);
                times.splice(i, 1);
                i--;
            } else {
                break;
            }
        };
        response.success("Got " + results.length + " Query results: " + results[0].objectId);

    },
    error: function(error) {
        response.error("Request failed with response code");
        console.error("Request failed with response code ");
    }
});
});

It tell's me that timestamps is undefined:

I2015-11-27T17:00:03.419Z]Deployed v17 with triggers:
Jobs:
    expireTimes
E2015-11-27T17:01:04.489Z]v17 Ran job expireTimes with:
  Input: {}
  Result: ReferenceError: timestamps is not defined
    at e.query.find.success (main.js:9:24)
    at e.<anonymous> (Parse.js:14:28224)
    at e.s (Parse.js:14:27156)
    at e.n.value (Parse.js:14:26575)
    at e.s (Parse.js:14:27284)
    at e.n.value (Parse.js:14:26575)
    at e.s (Parse.js:14:27284)
    at e.n.value (Parse.js:14:26575)
    at e.<anonymous> (Parse.js:14:27228)
    at e.s (Parse.js:14:27156)

Not sure what this means / how to fix it. I would assume declare timestamps, but I thought that was already done with the retrieval of the arrays in the columns "times" and "timestamp"

Any help would be much appreciated. Thank you

1 Answer 1

1

There's no such idea as query.select(). The only defined variables within the completion function are results (the array of retrieved parse objects) and currentTime, which you define in the enclosing scope.

The registerSubclass isn't useful unless you're actually defining a subclass.

As a starting exercise, try querying the class and logging the results. The query can be as simple as:

var query = new Parse.Query("Wait");
query.find().then(function(results) {
    console.log(JSON.stringify(results));
    var firstId = (results.length>0)? results[0].id : "n/a";  // notice "id", not "objectId"
    console.log("Got " + results.length + " First id: " + firstId);
    response.success(results);
}, function(error) {
    response.error(error);  // return the real error so we can look at it
});

If timestamp is a defined attribute on your Wait class, you can get it with get()...

// just like before where you got the id, try "getting" an attribute
var firstTimestamp = (results.length>0)? results[0].get("timestamp") : "n/a";
// remember, this depends on you defining a "timestamp" attribute on the class
Sign up to request clarification or add additional context in comments.

6 Comments

Both timestamp and times are arrays. times takes the user's time that they have submitted and timestamp just simply takes the time the user submitted it and puts it into an Int. That way, I can see if the timestamp + 3600 < currentTime and if it is, I delete it. So how do I grab those array's and run my for loop?
Not sure if this is helpful, but remember that all parse objects provide createdAt and updatedAt, and that queries can compare these with equality (but usually better) inequality, like query.lessThan("updatedAt", someDate), where someDate is a JS date object.
Also note that array properties can be gotten with get() and their contents looped like any JS array.
Perfect. So now that I have changed my code here, how do I get it to actually delete and update the arrays in the object?
Got it. I'll answer there. One quick question, though, do you really want to do this to only one Wait object -- the first one found, results[0]? Or do you want to change all of the Wait objects found?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.