0

A bit new to JS. I'm using Parse.com's CloudCode in order to calculate the "score" of a "Post" instance. I retrieve any "Votes" associated with a post, and then sum up their "value", then return that value.

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

    var postId = request.params.postId;
    var post = Parse.Object.extend("Post");
    post.id = postId;

    var query = new Parse.Query("Vote");
    query.equalTo("post", post);

    query.find({
        success: function(results) {
          var sum = 0;
          for (var i = 0; i < results.length; ++i) {
            sum += results[i].get("value");
          }
          response.success(sum);
        },
        error: function() {
          response.error("Could not calculate value");
        }
      });
});

Getting this error:

2014-05-02 19:21:09.124 XXX[33361:2d3b] Error: undefined (Code: 141, Version: 1.2.19)

Not too sure what the issue is.

Calling it in my iOS app like so:

- (void)fetchPostScores
{
  for (BVYPost *post in _postsArray) {
    [PFCloud callFunctionInBackground:@"postScore" withParameters:@{@"postId": post.objectId} block:^(NSNumber *score, NSError *error) {
      if (!error) {
        post.score = score;
      }
    }];
  }
}

1 Answer 1

1

This is wrong:

var post = Parse.Object.extend("Post");
post.id = postId;

The correct syntax would be:

var post = new Parse.Object("Post");
post.id = postId;
Sign up to request clarification or add additional context in comments.

1 Comment

I have made the change, and still receive a (different) error. 2014-05-02 21:07:36.198 Bevy[34776:384b] Error: Could not calculate value (Code: 141, Version: 1.2.19) and 2014-05-02 21:05:41.306 Bevy[34776:60b] Warning: A long-running Parse operation is being executed on the main thread. Break on warnParseOperationOnMainThread() to debug.

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.