-1

I am just trying to check if user_id and comment_id is there in my database table and if they exists, then do x operation or else y operation. And, I am taking this user_id and comment_id at the runtime from the user. So how should I write my if condition using query.equalTo so that I can do my respective operations. Below is the code of what I am trying to do.

Parse.Cloud.define("voteForComment", function(request, response) 
{     
   var insertVote = Parse.Object.extend("trans_Votes");
    var vote = new insertVote();  
    var query = new Parse.Query("trans_Votes");
   if(query.equalTo("user_id", 
{
        __type: "Pointer",
        className: "_User",
        objectId: request.params.user_id 
})) && (query.equalTo("comment_id",
{ __type: "Pointer",
        className: "mst_Comment",
        objectId: request.params.comment_id
})); // how to write this two equalTo queries..(its showing error)
    { 
      
query.find
({
   success : function(rec)
   {
     X operation here  
   },
   error : function(error)
   {
     response.error(error);
   `}
     });
      }
else
{
 y operation here
}

Thanks.

Geek_KK
  • 192
  • 2
  • 11

1 Answers1

2

Your parentheses are a bit of a mess. Removing the equalTo() function calls from the if statement leaves us with this code wireframe:

if (...) && (...);
{
    ...
} else {
    ...
}

This is not going to work because of the syntax errors. We need to change it a bit:

if ((...) && (...))
{
    ...
} else {
    ...
}

Applying these changes to your code results in this:

if (query.equalTo("user_id", {
    __type: "Pointer",
    className: "_User",
    objectId: request.params.user_id 
}) && query.equalTo("comment_id", {
    __type: "Pointer",
    className: "mst_Comment",
    objectId: request.params.comment_id
})) { 
    query.find({
        success: function(rec) {
            X operation here  
        },
        error: function(error) {
            response.error(error);
        }
    });
} else {
    y operation here
}

That should work.

Antti29
  • 2,953
  • 12
  • 34
  • 36
  • 1
    @ketanpande Feel free to upvote and mark as accepted if the answer was useful and solved your problem. – Antti29 May 26 '16 at 06:37
  • The OP is a serial asker of poorly formed questions, and an absentee on good answers. – danh Jul 05 '16 at 15:17