modules/query/CalendarTable.js
function getServicesEffective(db, date, callback) {

  // Check Cache for Effective Services
  let cacheKey = db.id + "-" + date;
  let cache = cache_servicesEffectiveByDate.get(cacheKey);
  if ( cache !== null ) {
    return callback(null, cache);
  }

  // Get the Default Services
  getServicesDefault(db, date, function(defaultError, defaultServices) {

    // Get the Service Exceptions
    getServiceExceptions(db, date, function(exceptionsError, serviceExceptions) {


      // Check for Default Services Error
      if ( defaultError ) {
        return callback(defaultError);
      }

      // Check for Service Exceptions Error
      if ( exceptionsError ) {
        return callback(exceptionsError);
      }


      // List of Service IDs to Add to Default Services
      let serviceIdsToAdd = [];

      // Parse the exceptions
      for ( let i = 0; i < serviceExceptions.length; i++ ) {
        let serviceException = serviceExceptions[i];

        // Exception Type: Added
        if ( serviceException.exceptionType === ServiceException.SERVICE_ADDED ) {

          // Make sure service isn't already in list
          let found = false;
          for ( let j = 0; j < defaultServices.length; j++ ) {
            if ( defaultServices[j].id === serviceException.serviceId ) {
              found = true;
            }
          }

          // Flag Service ID to add
          if ( !found ) {
            serviceIdsToAdd.push(serviceException.serviceId);
          }

        }

        // Exception Type: Removed
        else if ( serviceException.exceptionType === ServiceException.SERVICE_REMOVED ) {

          // Find matching default service
          let removeIndex = -1;
          for ( let j = 0; j < defaultServices.length; j++ ) {
            if ( defaultServices[j].id === serviceException.serviceId ) {
              removeIndex = j;
            }
          }

          // Remove the matching service from default services list
          if ( removeIndex !== -1 ) {
            defaultServices.splice(removeIndex, 1);
          }

        }

      }


      // Add services, if we need to
      if ( serviceIdsToAdd.length > 0 ) {
        getService(db, serviceIdsToAdd, function(err, services) {

          // Error Getting Services
          if ( err ) {
            return callback(err);
          }

          // Add Services to list
          for (let i = 0; i < services.length; i++) {
            let service = services[i];
            defaultServices.push(service);
          }

          // Add Services to Cache
          cache_servicesEffectiveByDate.put(cacheKey, defaultServices);

          // Return Services
          return callback(null, defaultServices);

        });
      }

      // Return Default Services
      else {

        // Add Services to Cache
        cache_servicesEffectiveByDate.put(cacheKey, defaultServices);

        return callback(null, defaultServices);

      }


    });

  });

}
function getServicesEffective(db, date, callback) {

  // Check Cache for Effective Services
  let cacheKey = db.id + "-" + date;
  let cache = cache_servicesEffectiveByDate.get(cacheKey);
  if ( cache !== null ) {
    return callback(null, cache);
  }

  // Get the Default Services
  getServicesDefault(db, date, function(defaultError, defaultServices) {

    // Get the Service Exceptions
    getServiceExceptions(db, date, function(exceptionsError, serviceExceptions) {


      // Check for Default Services Error
      if ( defaultError ) {
        return callback(defaultError);
      }

      // Check for Service Exceptions Error
      if ( exceptionsError ) {
        return callback(exceptionsError);
      }


      // List of Service IDs to Add to Default Services
      let serviceIdsToAdd = [];

      // Parse the exceptions
      for ( let i = 0; i < serviceExceptions.length; i++ ) {
        let serviceException = serviceExceptions[i];

        // Exception Type: Added
        if ( serviceException.exceptionType === ServiceException.SERVICE_ADDED ) {

          // Make sure service isn't already in list
          let found = false;
          for ( let j = 0; j < defaultServices.length; j++ ) {
            if ( defaultServices[j].id === serviceException.serviceId ) {
              found = true;
            }
          }

          // Flag Service ID to add
          if ( !found ) {
            serviceIdsToAdd.push(serviceException.serviceId);
          }

        }

        // Exception Type: Removed
        else if ( serviceException.exceptionType === ServiceException.SERVICE_REMOVED ) {

          // Find matching default service
          let removeIndex = -1;
          for ( let j = 0; j < defaultServices.length; j++ ) {
            if ( defaultServices[j].id === serviceException.serviceId ) {
              removeIndex = j;
            }
          }

          // Remove the matching service from default services list
          if ( removeIndex !== -1 ) {
            defaultServices.splice(removeIndex, 1);
          }

        }

      }


      // Add services, if we need to
      if ( serviceIdsToAdd.length > 0 ) {
        getService(db, serviceIdsToAdd, function(err, services) {

          // Error Getting Services
          if ( err ) {
            return callback(err);
          }

          // Add Services to list
          for (let i = 0; i < services.length; i++) {
            let service = services[i];
            defaultServices.push(service);
          }

          // Add Services to Cache
          cache_servicesEffectiveByDate.put(cacheKey, defaultServices);

          // Return Services
          return callback(null, defaultServices);

        });
      }

      // Return Default Services
      else {

        // Add Services to Cache
        cache_servicesEffectiveByDate.put(cacheKey, defaultServices);

        return callback(null, defaultServices);

      }


    });

  });

}
function getServicesEffective ( db , date , callback ) { // Check Cache for Effective Services let cacheKey = db . id + "-" + date ; let cache = cache_servicesEffectiveByDate . get ( cacheKey ) ; if ( cache !== null ) { return callback ( null , cache ) ; } // Get the Default Services getServicesDefault ( db , date , function ( defaultError , defaultServices ) { // Get the Service Exceptions getServiceExceptions ( db , date , function ( exceptionsError , serviceExceptions ) { // Check for Default Services Error if ( defaultError ) { return callback ( defaultError ) ; } // Check for Service Exceptions Error if ( exceptionsError ) { return callback ( exceptionsError ) ; } // List of Service IDs to Add to Default Services let serviceIdsToAdd = [ ] ; // Parse the exceptions for ( let i = 0 ; i < serviceExceptions . length ; i ++ ) { let serviceException = serviceExceptions [ i ] ; // Exception Type: Added if ( serviceException . exceptionType === ServiceException . SERVICE_ADDED ) { // Make sure service isn't already in list let found = false ; for ( let j = 0 ; j < defaultServices . length ; j ++ ) { if ( defaultServices [ j ] . id === serviceException . serviceId ) { found = true ; } } // Flag Service ID to add if ( ! found ) { serviceIdsToAdd . push ( serviceException . serviceId ) ; } } // Exception Type: Removed else if ( serviceException . exceptionType === ServiceException . SERVICE_REMOVED ) { // Find matching default service let removeIndex = - 1 ; for ( let j = 0 ; j < defaultServices . length ; j ++ ) { if ( defaultServices [ j ] . id === serviceException . serviceId ) { removeIndex = j ; } } // Remove the matching service from default services list if ( removeIndex !== - 1 ) { defaultServices . splice ( removeIndex , 1 ) ; } } } // Add services, if we need to if ( serviceIdsToAdd . length > 0 ) { getService ( db , serviceIdsToAdd , function ( err , services ) { // Error Getting Services if ( err ) { return callback ( err ) ; } // Add Services to list for ( let i = 0 ; i < services . length ; i ++ ) { let service = services [ i ] ; defaultServices . push ( service ) ; } // Add Services to Cache cache_servicesEffectiveByDate . put ( cacheKey , defaultServices ) ; // Return Services return callback ( null , defaultServices ) ; } ) ; } // Return Default Services else { // Add Services to Cache cache_servicesEffectiveByDate . put ( cacheKey , defaultServices ) ; return callback ( null , defaultServices ) ; } } ) ; } ) ; }
Get the Services in effect on the specified date.  This includes
any exceptions found in the calendar_dates file.

@param {RightTrackDB} db The Right Track Database to query
@param {int} date The date to query (yyyymmdd)
@param {function} callback Callback function
@param {Error} callback.error Database Query Error
@param {Service[]} callback.services The selected Services
Get the Services in effect on the specified date . This includes any exceptions found in the calendar_dates file .