giorgionasis
giorgionasis

Reputation: 394

Parse Cloud Code returns Parse Objects not allowed here

I am trying to retrieve data from the Database of Parse Server and I am facing a 500 Internal Error.

My class is "Friends" and the column is "fromUser", which is a Pointer to <_User> class.

The point is to get the usernames from the column "username" which is inside of the "User" Class.

I develop the app with Ionic 3 and trying to run the function with a current user logged in to retrieve the data.

My cloud code:

Parse.Cloud.define('FriendsQuery', function(req,res) {
const query = new Parse.Query("Friends");
query.equalTo("fromUser", request.params.currentuser);
query.find().then((results) => {
    res.success(results);
})
.catch(() =>  {
  response.error("user lookup failed");
});
});

and my typescript code

currentUser = Parse.User.current();
retrieveFriends(){
if (this.currentUser= Parse.User.current()) {
  const passdata = Parse.User.current();
  Parse.Cloud.run('FriendsQuery', {currentuser: this.currentUser }).then(
  res => {
    console.log(res)
    }
  )
}

}

Any ideas?

Upvotes: 2

Views: 633

Answers (2)

Marcos T. Gobriel
Marcos T. Gobriel

Reputation: 121

so please try this

Parse.Cloud.define('FriendsQuery', function(req,res) {
var currentId =  req.params.currentuser;
var currentuserquery = new Parse.Query(Parse.User);
    currentuserquery.equalTo("objectId", currentId);  // find all the women
    currentuserquery.first({
      success: function(user) {
      const query = new Parse.Query("Friends");
      query.equalTo("fromUser", user);
      query.find().then((results) => {
      res.success(results);
      })

      }
    })

.catch(() =>  {
  res.error("user lookup failed");
});
});

Upvotes: 0

Marcos T. Gobriel
Marcos T. Gobriel

Reputation: 121

for parse cloud code objects not allowed so you have to send only the user id and do a query in cloud to get the user object like the following

typescript code:

    currentUser = Parse.User.current();
retrieveFriends(){
if (this.currentUser= Parse.User.current()) {
  const passdata = Parse.User.current();
  Parse.Cloud.run('FriendsQuery', {currentuser: this.currentUser.id }).then(
  res => {
    console.log(res)
    }
  )
}
}

cloud code:

    Parse.Cloud.define('FriendsQuery', function(req,res) {
const query = new Parse.Query("Friends");
var currentId =  req.params.currentuser;
var currentuserobject = {};
 var currentuserquery = new Parse.Query(Parse.User);
    currentuserquery.equalTo("objectId", currentId);  // find all the women
    currentuserquery.first({
      success: function(user) {
        user = currentuserobject;
      }
    });
query.equalTo("fromUser", currentuserobject);
query.find().then((results) => {
    res.success(results);
})
.catch(() =>  {
  response.error("user lookup failed");
});
});

Upvotes: 0

Related Questions