modules/query/TripsTable.js
function getTripByDeparture(db, originId, destinationId, departure, callback) {

  // Check cache for trip
  let cacheKey = db.id + "-" + originId + "-" + destinationId + "-" + departure.getTimeSeconds() + "-" + departure.getDateInt();
  let cache = cache_tripsByDeparture.get(cacheKey);
  if ( cache !== null ) {
    return callback(null, cache);
  }

  // Check to make sure both origin and destination have IDs set
  if ( originId === "" || originId === undefined ||
      destinationId === "" || destinationId === undefined ) {
    return callback(
      new Error('Could not get Trip, origin and/or destination id not set')
    );
  }


  // ORIGINAL DEPARTURE DATE
  _getTripByDeparture(db, originId, destinationId, departure, function(err, trip) {
    if ( err ) {
      return callback(err);
    }

    // Trip Found...
    if ( trip !== undefined ) {
      cache_tripsByDeparture.put(cacheKey, trip);
      return callback(null, trip);
    }


    // PREVIOUS DEPARTURE DATE, +24 HOUR TIME
    let prev = DateTime.create(
      departure.getTimeSeconds() + 86400,
      departure.clone().deltaDays(-1).getDateInt()
    );

    _getTripByDeparture(db, originId, destinationId, prev, function(err, trip) {

      // Return results
      cache_tripsByDeparture.put(cacheKey, trip);
      return callback(err, trip);

    });


  });

}
function getTripByDeparture(db, originId, destinationId, departure, callback) {

  // Check cache for trip
  let cacheKey = db.id + "-" + originId + "-" + destinationId + "-" + departure.getTimeSeconds() + "-" + departure.getDateInt();
  let cache = cache_tripsByDeparture.get(cacheKey);
  if ( cache !== null ) {
    return callback(null, cache);
  }

  // Check to make sure both origin and destination have IDs set
  if ( originId === "" || originId === undefined ||
      destinationId === "" || destinationId === undefined ) {
    return callback(
      new Error('Could not get Trip, origin and/or destination id not set')
    );
  }


  // ORIGINAL DEPARTURE DATE
  _getTripByDeparture(db, originId, destinationId, departure, function(err, trip) {
    if ( err ) {
      return callback(err);
    }

    // Trip Found...
    if ( trip !== undefined ) {
      cache_tripsByDeparture.put(cacheKey, trip);
      return callback(null, trip);
    }


    // PREVIOUS DEPARTURE DATE, +24 HOUR TIME
    let prev = DateTime.create(
      departure.getTimeSeconds() + 86400,
      departure.clone().deltaDays(-1).getDateInt()
    );

    _getTripByDeparture(db, originId, destinationId, prev, function(err, trip) {

      // Return results
      cache_tripsByDeparture.put(cacheKey, trip);
      return callback(err, trip);

    });


  });

}
function getTripByDeparture ( db , originId , destinationId , departure , callback ) { // Check cache for trip let cacheKey = db . id + "-" + originId + "-" + destinationId + "-" + departure . getTimeSeconds ( ) + "-" + departure . getDateInt ( ) ; let cache = cache_tripsByDeparture . get ( cacheKey ) ; if ( cache !== null ) { return callback ( null , cache ) ; } // Check to make sure both origin and destination have IDs set if ( originId === "" || originId === undefined || destinationId === "" || destinationId === undefined ) { return callback ( new Error ( 'Could not get Trip, origin and/or destination id not set' ) ) ; } // ORIGINAL DEPARTURE DATE _getTripByDeparture ( db , originId , destinationId , departure , function ( err , trip ) { if ( err ) { return callback ( err ) ; } // Trip Found... if ( trip !== undefined ) { cache_tripsByDeparture . put ( cacheKey , trip ) ; return callback ( null , trip ) ; } // PREVIOUS DEPARTURE DATE, +24 HOUR TIME let prev = DateTime . create ( departure . getTimeSeconds ( ) + 86400 , departure . clone ( ) . deltaDays ( - 1 ) . getDateInt ( ) ) ; _getTripByDeparture ( db , originId , destinationId , prev , function ( err , trip ) { // Return results cache_tripsByDeparture . put ( cacheKey , trip ) ; return callback ( err , trip ) ; } ) ; } ) ; }
Find the Trip that leaves the specified origin Stop for the specified
destination Stop at the departure time specified by the DateTime
@param {RightTrackDB} db The Right Track DB to query
@param {string} originId Origin Stop ID
@param {string} destinationId Destination Stop ID
@param {DateTime} departure DateTime of trip departure
@param {function} callback Callback function
@param {Error} callback.error Database Query Error
@param {Trip} [callback.trip] The selected Trip
Find the Trip that leaves the specified origin Stop for the specified destination Stop at the departure time specified by the DateTime