title: How to return mysql data to caller? Something works, other case don't work?
body: <p>It is my db object code(DBO.js):</p>
  <pre><code>class DBO
  {
      constructor(){
          let dbConfig = require('./config');
          dbConfig[&quot;multipleStatements&quot;]=true;
          const moment = require('moment');
          const mysql = require('mysql2');
          const connection = mysql.createConnection(dbConfig);
          
          this.getITOList=(year,month,callBack)=&gt;{
              const startDateString=year+&quot;-&quot;+month+&quot;-01&quot;;
              const endDateString=moment(startDateString).add(1,&quot;M&quot;).add(-1,&quot;d&quot;).format('YYYY-MM-DD');
              
              let sqlString =&quot;SELECT join_date,leave_date,ito_info.ito_id,post_name,ito_name,available_shift,working_hour_per_day,black_list_pattern from &quot;;
              sqlString+=&quot;ito_info inner join black_list_pattern &quot;;
              sqlString+=&quot;on ito_info.ito_id=black_list_pattern.ito_id &quot;;
              sqlString+=&quot;where join_date&lt;=? and leave_date &gt;=? &quot;;
              sqlString+=&quot;order by ito_info.ito_id&quot;;
              console.log(&quot;startDateString=&quot;+startDateString+&quot;,endDateString=&quot;+endDateString);
              connection.execute(sqlString,[startDateString,endDateString],(err, results, fields)=&gt;{
                  connection.end(err=&gt;{
                      if (err) {
                          throw err;
                      } else {
                          callBack(err,results);
                          console.log(&quot;Get ITO List successfully.&quot;);
                      }
                  });
              });
              
          }
          this.getRosterRule=(callBack)=&gt;{
              let sqlString =&quot;select * from roster_rule order by rule_type,rule_key,rule_value&quot;;
              connection.execute(sqlString,(err, results, fields)=&gt;{
                  connection.end(err=&gt;{
                      if (err) {
                          throw err;
                      } else {
                          callBack(err,results);
                          console.log(&quot;Get Roster Rule successfully!&quot;);
                      }
                  });
              });
          }
          this.close=()=&gt;{
              connection.end(err=&gt;{
                  if (err) throw err;
                  console.log(&quot;Disconnect form &quot;+process.env[&quot;DATABASE_HOST&quot;]+&quot; successfully!&quot;);
              });
          }       
      }
  }
  module.exports = DBO;
  </code></pre>
  <p>Here is the RosterRule Object:</p>
  <pre><code>class RosterRule{
      constructor(){
          let DBO=require(&quot;../utils/dbo.js&quot;);
          let dboObj=new DBO();
          this.essentialShiftList=null;   
          this.maxConsecutiveWorkingDay=0;
          this.shiftHourCount={};     
          dboObj.getRosterRule((err,resultList)=&gt;{
              if (err){
                  throw err;
              }else {
                  resultList.forEach(result=&gt;{
                      switch (result.rule_type){
                          case 'ConsecutiveWorkingDay':
                              this.maxConsecutiveWorkingDay=parseInt(result.rule_value);
                              break;
                          case 'shiftHour':
                              this.shiftHourCount[result.rule_key]=parseFloat(result.rule_value);
                              break;
                          case 'shiftList':
                              var temp=result.rule_value.replace(/&quot;/g,'');
                              this.essentialShiftList=temp.split(',');
                              break;
                      }
                  });
              }
          });
          
      }
  }
  module.exports =new RosterRule();
  </code></pre>
  <p>Here is an ITO Object.</p>
  <pre><code>class ITO
  {
      constructor(){
          /**
           * The ITO Id of the specified ITO.
           */
          this.itoId=&quot;&quot;;
          /**
           * The name of the specified ITO.
           */
          this.itoName=&quot;&quot;;
          /**
           * The post name of the specified ITO
           */
          this.postName=&quot;&quot;;
      
          /**
           * The total no. of working hour per day for the specified ITO.
           */
          this.workingHourPerDay=0.0;
          /**
           * The join date of the specified ITO.
           */
          this.joinDate=null;
          /**
           * The leave date of the specified ITO.
           */
          this.leaveDate=null;
          /**
           * The available shift list of the specified ITO.   
           */
          this.availableShiftList=[];
          /**
           * The black listed shift pattern list of the specified ITO.    
           */
          this.blackListedShiftPatternList=[];        
      }
      static getITOList(year, month){
          let DBO=require(&quot;../utils/dbo.js&quot;);
          let dboObj=new DBO();
          let resultObj={};
          dboObj.getITOList(year,month,(err,resultList)=&gt;{
              if (err){
                  throw err;
              }else {
                  resultList.forEach(ito=&gt;{
                      let itoObj;
                      if (resultObj[ito.ito_id]){
                          itoObj=resultObj[ito.ito_id];
                          itoObj.blackListedShiftPatternList.push(ito.black_list_pattern);
                      }else {
                          itoObj=new ITO();
                          itoObj.itoId=ito.ito_id;
                          itoObj.itoName=ito.ito_name;
                          itoObj.postName=ito.post_name;
                          itoObj.workingHourPerDay=ito.working_hour_per_day;
                          itoObj.joinDate=new Date(ito.join_date);
                          itoObj.leaveDate=new Date(ito.leave_date);
                          itoObj.availableShiftList=ito.available_shift.split(&quot;,&quot;);
                          itoObj.blackListedShiftPatternList.push(ito.black_list_pattern);
                      }
                      resultObj[ito.ito_id]=itoObj;
                  });
                  console.log(&quot;hi:&quot;+JSON.stringify(resultObj));
                  return resultObj;               
              }
          });
          
      }
  }
  module.exports = ITO;
  </code></pre>
  <p>Finally, this is RosterManager object code:</p>
  <pre><code>class RosterManager
  {
      constructor(){
          let DBO=require(&quot;../utils/dbo.js&quot;);
          let ITO=require(&quot;./ITO.js&quot;);
          const RosterRule = require('./RosterRule');
          this.getRosterList=(year,month)=&gt;{
              console.log(&quot;RosterRule:&quot;+RosterRule);
              let itoList=ITO.getITOList(year,month);
              console.log(itoList);
          }
      }
  }
  module.exports = RosterManager;
  </code></pre>
  <p>All the RosterRule attributes can be load from DB successfully.</p>
  <p>When the RosterManager.getRosterList is called, Why the return value is &quot;undefined&quot;?</p>
  <p>I have added the following statement in ITO, the DBO object has got the data from DB succesfully.</p>
  <pre><code>console.log(&quot;hi:&quot;+JSON.stringify(resultObj));
  </code></pre>
  <p>However, in the RosterManager object cannot read the data.</p>
  <p>Would you help to fix it?</p>