title: How to write this code in async/callbacks in nodejs?
body: <p>I am trying to perform SQL queries based on the callback results in if conditions but I am unable to write the code. So can somebody please provide some information how to do this with async/callback methods?</p>
  
  <pre><code>app.get('/resell-property', function(req, res) {
      var data = {}
      data.unit_price_id = 1;
      function callback(error, result) {
          if (result.count == 0) {
              return hp_property_sell_request.create(data)
          } else if (result.count &gt; 0) {
              return hp_unit_price.findAll({
                  where: {
                      unit_price_id: data.unit_price_id,
                      hp_property_id: data.property_id,
                      hp_unit_details_id: data.unit_details_id
                  }
              })
          }
      }
  
  
      hp_property_sell_request.findAndCountAll({
          where: {
              unit_price_id: data.unit_price_id
          }
      }).then(function (result) {
          if (result) {
              callback(null, result);
          }
      });    
  });
  </code></pre>
  
  <p>How can I write the callbacks for this?</p>
  
  <pre><code>hp_property_sell_request.create(data) ,hp_unit_price.findAll({
      where: {
          unit_price_id: data.unit_price_id,
          hp_property_id: data.property_id,
          hp_unit_details_id: data.unit_details_id
      }
  })
  </code></pre>
  
  <p>After returning the result I want to handle callbacks and perform this query:</p>
  
  <pre><code>if (result.request_id) {
      return hp_unit_price.findAll({
          where: {
              unit_price_id:result.unit_price_id,
              hp_property_id:result.property_id,
              hp_unit_details_id:result.unit_details_id
          }
      }).then(function(result) {
          if (result.is_resale_unit==0 &amp;&amp; result.sold_out==0) {
              return Sequelize.query('UPDATE hp_unit_price SET resale_unit_status=1 WHERE hp_unit_details_id='+result.unit_details_id+' and  hp_property_id='+result.property_id)
          }
      })
  }
  </code></pre>