0

I do not have a clue why I cannot sterilize my user object array server side. I am having issues accessing any properties at all server side no matter what I've tried I get either errors or empty results. In my Flutter/Dart code I can access any properties as normal but of course I do not want users to be able to get all such data.

So the question is, why can't I access properties server side and how can I do this?

EDIT: On some help in comments it has been discovered that this "object" is not in fact an array, this makes things more difficult. Also does not make sense that I can access the "not array" normally in my flutter dart code... any ideas whats wrong?

For below I am following this My code that works, returning a list of Parse User objects:

Parse.Cloud.define("ccRoleUsersQuery", async function(request) {
    const query = await new Parse.Query(Parse.Role).equalTo('users', request.user).find({ useMasterKey: true })
    let users = query[0].getUsers().query().find({ useMasterKey: true });
    let steralizedResults = [];
    for (let i = 0; i < users.length; i++) {
        let name = users[i].get("name");         // Does not access object
      let publicKey = users[i]["publicKey"];     // Does not access object
      steralizedResults.push(name);          
      steralizedResults.push(publicKey);    
    }
    return users;            // steralizedResults if used returns empty array
  });

Users array returned as above:

[{username: user003, email: [email protected], createdAt: 2021-09-26T23:37:37.594Z,
updatedAt: 2021-10-05T01:25:43.989Z, publicKey: 445trTREttY654FFFGgt5ydfsg, name: 003, ACL: {6m9LPbxD8V: {read: true, write: true}}, objectId: 6m9LPbxD8V, __type: Object, className: _User}, 
{username: user004, createdAt: 2021-10-03T22:19:27.754Z, updatedAt: 2021-10-06T23:24:07.576Z, email: [email protected], publicKey: GTRg554gtr8yvfdsv43fdsv334, name:
004, ACL: {t9joISsGwO: {read: true, write: true}}, objectId: t9joISsGwO, __type: Object, className: _User}]

14
  • You are just returning the users. That being said I have no idea how that .find method works. It's not the same as Array.prototype.find, anyways. Commented Oct 7, 2021 at 0:11
  • Yes, just returning the users. It is very incomprehensible & mysterious as to why I can't access the objects server side... Commented Oct 7, 2021 at 0:15
  • console.log(typeof users). What do you get? Commented Oct 7, 2021 at 0:28
  • 2021-10-07T00:29:54.074Z - object Commented Oct 7, 2021 at 0:33
  • 1
    Also, is this not async? Should there not be an await or, as these docs propose, .find({ ..., success: list =>? (docs.parseplatform.org/js/guide) Commented Oct 7, 2021 at 1:25

1 Answer 1

1

'Tis the season to be async:

query.find({
  success: function(results) {
    // results is an array of Parse.Object.
  },
  error: function(error) {
    // error is an instance of Parse.Error.
  }
});

Also special functions you can use on the Parse.Query object: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/parse/index.d.ts (search for class Query)

Sign up to request clarification or add additional context in comments.

Comments

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.