Skip to content

Cloud Code Relation Field Query not working #1489

Closed
@ghost

Description

Okay I wrote a cloud function when using the parse dashboard which worked fine. We then switched to a parse server on heroku. The following code works up until it hits Parse.Relation(role, 'users'). The admins.first() runs the success function but with no users returned. I'm 100% positive it's connected to the correct DB and there are users with the 'admin' role, and I am querying a user with 'admin' role, but it's not finding it and returns undefined. Is this an issue with the new Parse server setup?

Parse.Cloud.define('isAdmin', function(req, response){
  Parse.Cloud.useMasterKey();
  if(!req.params.username){
    response.error('no username');
  }

  var queryRole = new Parse.Query(Parse.Role);
  queryRole.equalTo('name','admin');

  queryRole.first({
    success: function(promise){
      var role = promise;
      var relation = new Parse.Relation(role, 'users');
      var admins = relation.query();
      admins.equalTo('username', req.user.get('username'));
      admins.first({
        success: function(u){
          var user = u;
          if(user) {
            response.success('User is admin')
          }
          else {
            response.error('User is not Admin')
          }
        },
        error: function(){
          response.error('Error on user lookup')
        }
      })
    },
    error: function(){
      response.error('Error on role lookup')
    }
  })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions