<file_sep>let travelers = [
  {
    "id": 15,
    "name": "<NAME>",
    "travelerType": "relaxer"
  },
  {
    "id": 26,
    "name": "<NAME>",
    "travelerType": "thrill-seeker"
  },
  {
    "id": 13,
    "name": "<NAME>",
    "travelerType": "shopper"
  },
  {
    "id": 43,
    "name": "<NAME>",
    "travelerType": "photographer"
  },
  {
    "id": 95,
    "name": "<NAME>",
    "travelerType": "thrill-seeker"
  },
  {
    "id": 63,
    "name": "<NAME>",
    "travelerType": "shopper"
  },
  {
    "id": 27,
    "name": "<NAME>",
    "travelerType": "relaxer"
  },
  {
    "id": 81,
    "name": "<NAME>",
    "travelerType": "history buff"
  },
  {
    "id": 59,
    "name": "<NAME>",
    "travelerType": "relaxer"
  },
  {
    "id": 100,
    "name": "<NAME>",
    "travelerType": "relaxer"
  }
]

let trips = [
  {
    "id": 1,
    "userID": 15,
    "destinationID": 44,
    "travelers": 1,
    "date": "2021/04/20",
    "duration": 4,
    "status": "approved",
    "suggestedActivities": ["swimming"],
    "estimatedLodgingCostPerDay": 450,
    "estimatedFlightCostPerPerson": 80
  }, {
    "id": 2,
    "userID": 15,
    "destinationID": 22,
    "travelers": 4,
    "date": "2020/10/04",
    "duration": 18,
    "status": "pending",
    "suggestedActivities": ["swim with dolphins"],
    "estimatedLodgingCostPerDay": 90,
    "estimatedFlightCostPerPerson": 650
  }, {
    "id": 3,
    "userID": 15,
    "destinationID": 12,
    "travelers": 3,
    "date": "2020/05/22",
    "duration": 17,
    "status": "pending",
    "suggestedActivities": ["swimming"],
    "estimatedLodgingCostPerDay": 150,
    "estimatedFlightCostPerPerson": 1200
  }, {
    "id": 43,
    "userID": 15,
    "destinationID": 14,
    "travelers": 2,
    "date": "2022/02/25",
    "duration": 10,
    "status": "approved",
    "suggestedActivities": ["zip-lining"],
    "estimatedLodgingCostPerDay": 70,
    "estimatedFlightCostPerPerson": 830
  }, {
    "id": 15,
    "userID": 95,
    "destinationID": 29,
    "travelers": 3,
    "date": "2020/04/30",
    "duration": 18,
    "status": "approved",
    "suggestedActivities": ["hiking"],
    "estimatedLodgingCostPerDay": 80,
    "estimatedFlightCostPerPerson": 1100
  }, {
    "id": 23,
    "userID": 27,
    "destinationID": 35,
    "travelers": 3,
    "date": "2020/06/29",
    "duration": 9,
    "status": "approved",
    "suggestedActivities": ["swimming"],
    "estimatedLodgingCostPerDay": 80,
    "estimatedFlightCostPerPerson": 1100
  }, {
    "id": 7,
    "userID": 27,
    "destinationID": 17,
    "travelers": 5,
    "date": "2020/5/28",
    "duration": 20,
    "status": "approved",
    "suggestedActivities": ["hiking"],
    "estimatedLodgingCostPerDay": 30,
    "estimatedFlightCostPerPerson": 1200
  }, {
    "id": 4,
    "userID": 81,
    "destinationID": 39,
    "travelers": 6,
    "date": "2021/02/07",
    "duration": 4,
    "status": "approved",
    "suggestedActivities": ["bike-riding"],
    "estimatedLodgingCostPerDay": 995,
    "estimatedFlightCostPerPerson": 90
  }, {
    "id": 80,
    "userID": 2,
    "destinationID": 19,
    "travelers": 5,
    "date": "2019/12/19",
    "duration": 19,
    "status": null,
    "suggestedActivities": null,
    "estimatedLodgingCostPerDay": 60,
    "estimatedFlightCostPerPerson": 500
  }, {
    "id": 70,
    "userID": 100,
    "destinationID": 50,
    "travelers": 6,
    "date": "2017/07/23",
    "duration": 17,
    "status": "approved",
    "suggestedActivities": ["reading"],
    "estimatedLodgingCostPerDay": 1400,
    "estimatedFlightCostPerPerson": 75
  }
]

export { travelers, trips }
<file_sep>const dayjs = require('dayjs')
dayjs().format()
const isBetween = require('dayjs/plugin/isBetween');
dayjs.extend(isBetween);


class Traveler {
  constructor(travelerInfo) {
    this.id = travelerInfo.id;
    this.name = travelerInfo.name;
    this.travelerType = travelerInfo.travelerType;
    this.myTrips;
    this.myCurrentTrip;
    this.myPastTrips = [];
    this.myFutureTrips = [];
    this.myPendingTrips = [];
    this.myTripsInLastYear = [];
  }

  sortMyTrips(myTrips) {
    this.myTrips = myTrips;
    this.findPendingTrips();
    const todaysDate = dayjs().format('YYYY/MM/DD');
    this.sortByType(todaysDate, myTrips);
  }

  findPendingTrips() {
    const pendingTrips = this.myTrips.filter(trip => trip.status === 'pending');
    this.myPendingTrips = pendingTrips;
  }

  sortByType(date, trips) {
    trips.forEach(trip => {
      let endDate = dayjs(trip.date).add(trip.duration, 'day').format('YYYY/MM/DD');
      if (trip.status !== 'pending') {
        if (dayjs(date).isBetween(trip.date, endDate, null, [])) {
          this.myCurrentTrip = trip;
        } else if (dayjs(date).isBefore(trip.date)) {
          this.myFutureTrips.push(trip);
        } else if (dayjs(endDate).isBefore(date)) {
          this.myPastTrips.push(trip);
        }
      }
    })
  }

  findTripsInLastYear(todaysDate) {
    const oneYearAgo = dayjs(todaysDate).subtract(1, 'year').format('YYYY/MM/DD');
    this.myTrips.forEach(trip => {
      if (dayjs(trip.date).isBetween(oneYearAgo, todaysDate, null, [])) {
        this.myTripsInLastYear.push(trip);
      }
    })
  }

  calculateSpentOnTripsThisYear(todaysDate) {
    this.findTripsInLastYear(todaysDate);
    if (!this.myTripsInLastYear.length) {
      return "You haven't traveled with us recently! We'd love to help you book your next trip!";
    } else {
      const cost = this.myTripsInLastYear.reduce((sum, trip) => {
        sum += (trip.duration * trip.estimatedLodgingCostPerDay)
                + (trip.travelers * trip.estimatedFlightCostPerPerson);
        return sum;
      }, 0)
      const totalCost = (cost * 0.1) + cost;
      const finalCost = Number.parseFloat(totalCost).toFixed(2);
      return `You spent $${finalCost} on trips in the last year!`;
    }
  }

  addTrip(property, trip) {
    this[property].push(trip);
  }

}


export default Traveler;
<file_sep>const dayjs = require('dayjs')
dayjs().format()
const isBetween = require('dayjs/plugin/isBetween');
dayjs.extend(isBetween);


const domUpdates = {
  displayUserNameErrorMessage() {
    document.getElementById('userNameErrorMessage').innerText = "Please try your username again!";
  },

  clearUserNameErrorMessage() {
    document.getElementById('userNameErrorMessage').innerText = "";
  },

  displayPasswordErrorMessage() {
    document.getElementById('passwordErrorMessage').innerText = "Please try your password again!";
  },

  greetUser(traveler) {
    let firstName = traveler.name.split(' ')[0];
    document.getElementById('userGreeting').innerHTML = `Welcome back, ${firstName}!`;
  },

  hideLogInForm() {
    document.querySelector('.user-sign-in').classList.add('hidden');
    document.getElementById('userDashboard').classList.remove('hidden');
    document.getElementById('userGreeting').classList.remove('hidden');
  },


  displayTrips(traveler) {
    const myTripsDisplay = document.getElementById('tripsDisplayArea');
    const userPastTrips = document.getElementById('userPastTrips');
    const userPresentTrip = document.getElementById('userPresentTrip');
    const userFutureTrips = document.getElementById('userUpcomingTrips');
    const userPendingTrips = document.getElementById('userPendingTrips');
    if (!traveler.myTrips) {
      myTripsDisplay.innerText = "Book your first trip with us!";
    }
    if (traveler.myPastTrips.length === 0) {
      userPastTrips.innerText = "😯 You don't have any past trips! 😯";
    } else if (traveler.myPastTrips) {
      domUpdates.renderUserTripCards(traveler.myPastTrips, userPastTrips);
    }
    if (!traveler.myCurrentTrip) {
      userPresentTrip.innerText = "🏠 You're stuck at home for now! 🏠";
    } else if (traveler.myCurrentTrip) {
      domUpdates.renderUserTripCards(traveler.myCurrentTrip, userPresentTrip);
    }
    if (traveler.myFutureTrips.length === 0) {
      userFutureTrips.innerText = "😩 You don't have any upcoming trips! 😩";
    } else if (traveler.myFutureTrips) {
      domUpdates.renderUserTripCards(traveler.myFutureTrips, userFutureTrips);
    }
    if (traveler.myPendingTrips.length === 0) {
      userPendingTrips.innerText = "😭 You don't have any pending trips! 😭";
    } else {
      domUpdates.renderUserTripCards(traveler.myPendingTrips, userPendingTrips);
    }
  },

  renderUserTripCards(filteredTrips, pageArea) {
    pageArea.innerHTML = '';
    let tripCardsToDisplay = '';
    filteredTrips.forEach(trip => {
      let endDate = dayjs(trip.date).add(trip.duration, 'day').format('YYYY/MM/DD');
      tripCardsToDisplay +=
        `<article class="card">
        <div class="upper-card">
         <img class="location-pic" src=${trip.image} alt=${trip.alt}>
        </div>
        <div class="lower-card">
          <p class="location">${trip.destination}</p>
          <p class="dates">${trip.date} - ${endDate}</p>
        </div>
      </article>`
    })
    pageArea.innerHTML = tripCardsToDisplay;
  },

  displayTotalSpent(traveler) {
    const todaysDate = dayjs().format('YYYY/MM/DD');
    const totalAmount = traveler.calculateSpentOnTripsThisYear(todaysDate);
    document.getElementById('moneySpent').innerText = totalAmount;
  },

  displayDestinationCards(destinationData) {
    let destinationCardsToDisplay = '';
    destinationData.forEach(trip => {
      destinationCardsToDisplay +=
        `<article class="card">
      <div class="upper-card">
       <img class="location-pic" src=${trip.image} alt=${trip.alt}>
      </div>
      <div class="lower-card">
        <p class="location">${trip.destination}</p>
      </div>
    </article>`
    });
    document.getElementById('destinationsDisplay').innerHTML = destinationCardsToDisplay;
  },

  displayDestinationDropdownOptions(destinationData) {
    let destinationDropdownOptions = '';
    destinationData.forEach(trip => {
      destinationDropdownOptions +=
        `<option value="${trip.destination}">`
    });
    document.getElementById('destinations').innerHTML = destinationDropdownOptions;
  },

  displayTripEstimate(estimate) {
    document.getElementById('tripEstimate').innerText = `This trip will cost $${estimate}, including agent's fee. Book now!`;
  },

  displayDateErrorMessage(date) {
    document.getElementById('tripEstimate').innerText = `Please choose a departure date after ${date}`;
  },

  displayNumberErrorMessage(category) {
    if (category === 'durationInput') {
      document.getElementById('tripEstimate').innerText = "Please enter a valid number for duration of trip.";
    }
    if (category === 'travelersInput') {
      document.getElementById('tripEstimate').innerText = "Please enter a valid number for number of travelers.";
    }
  },

  displayDestinationErrorMessage() {
    document.getElementById('tripEstimate').innerText = "Please choose a valid destination."
  },

  clearErrorMessage() {
    document.getElementById('tripEstimate').innerText = '';
  },

  displayTripEstimateErrorMessage() {
    document.getElementById('tripEstimate').innerText = "Sorry, something went wrong! Please check your request inputs again!";
  },

  enableRequestButton() {
    if (document.querySelector('.submit-request').classList.contains('disable')) {
      document.querySelector('.submit-request').classList.remove('disable');
    }
  },

  toggleElement(element) {
    if (document.querySelector(element).classList.contains('disable')) {
      document.querySelector(element).classList.remove('disable');
    } else {
      document.querySelector(element).classList.add('disable');
    }
  },

  displayRequestSubmittedMessage() {
    document.getElementById('tripEstimate').innerText = 'Your trip has been submitted for approval by an agent!';
    domUpdates.toggleElement('.submit-request');
    domUpdates.toggleElement('.request-trip-form');
  },

  clearForm() {
    document.getElementById('tripEstimate').innerText = ''
    document.querySelector('.request-trip-form').reset();
    domUpdates.toggleElement('.request-trip-form');
  },

  displayCallUsErrorMessage() {
    document.getElementById('tripEstimate').innerText = 'We\'re sorry, something went wrong with your request.  Please try again later or call one of our travel agents at 1-800-555-5555!';
  },

  displayServerIsDownMessage() {
    document.getElementById('userGreeting').innerText = 'We\'re sorry, something went wrong!  Please try again later or call one of our travel agents at 1-800-555-5555!';
    document.getElementById('userDashboard').classList.add('hidden')
  }

}


export default domUpdates;
<file_sep>import Traveler from './traveler.js';
import Trip from './trip.js';
import domUpdates from './domUpdates.js';
import { fetchAllData, addNewTrip } from './networkRequests';
const dayjs = require('dayjs');
dayjs().format();
const isBetween = require('dayjs/plugin/isBetween');
dayjs.extend(isBetween);


//*******MEDIA QUERIES********//
const signInButton = document.getElementById('signIn');
const dateInput = document.getElementById('dateInput');
const tripDurationInput = document.getElementById('durationInput');
const numberOfTravelersInput = document.getElementById('travelersInput');
const destinationInput = document.getElementById('destinationInput');
const getEstimateButton = document.querySelector('.get-trip-estimate');
const submitRequestButton = document.querySelector('.submit-request');
let trips, destinations, singleTraveler, currentTraveler, pendingTrip;


//*******Event Listeners******//
signInButton.addEventListener('click', validateUserName);
destinationInput.addEventListener('keyup', filterDestinationsBySearch);
destinationInput.addEventListener('blur', checkDestinationInput);
dateInput.addEventListener('blur', checkDateInput);
tripDurationInput.addEventListener('blur', function() {
  checkNumbersInput('durationInput')
});
numberOfTravelersInput.addEventListener('blur', function() {
  checkNumbersInput('travelersInput')
});
getEstimateButton.addEventListener('click', validateFormInputs);
submitRequestButton.addEventListener('click', submitNewTripRequest);


//*******Functions******//
function validateUserName() {
  const userNameInput = document.getElementById('userName').value;
  const result = userNameInput.split('traveler');
  let userID;
  if (!result[0]) {
    userID = result[1];
  }
  if (0 < userID && userID < 51) {
    validatePassword(userID)
    domUpdates.clearUserNameErrorMessage();
  } else {
    domUpdates.displayUserNameErrorMessage();
  }
}

function validatePassword(userID) {
  const passwordInput = document.getElementById('password').value;
  if (passwordInput === '<PASSWORD>') {
    onPageLoad(userID);
    domUpdates.hideLogInForm();
  } else {
    domUpdates.displayPasswordErrorMessage();
  }
}

function onPageLoad(userID) {
  fetchAllData(userID)
    .then(allData => {
      trips = allData.tripsData
      destinations = allData.destinationsData
      singleTraveler = allData.singleTravelerData
      combineDataSets(trips, destinations)
      currentTraveler = new Traveler(singleTraveler)
      filterTripsByTraveler(singleTraveler.id)
      domUpdates.greetUser(currentTraveler)
      domUpdates.displayTrips(currentTraveler)
      domUpdates.displayTotalSpent(currentTraveler)
      domUpdates.displayDestinationCards(destinations.destinations)
      domUpdates.displayDestinationDropdownOptions(destinations.destinations)
    });
}

function combineDataSets(tripData, destinationData) {
  const result = tripData.trips.map(trip => {
    destinationData.destinations.forEach(destination => {
      if (trip.destinationID === destination.id) {
        trip['estimatedLodgingCostPerDay'] = destination.estimatedLodgingCostPerDay;
        trip['estimatedFlightCostPerPerson'] = destination.estimatedFlightCostPerPerson;
        trip['image'] = destination.image;
        trip['alt'] = destination.alt;
        trip['destination'] = destination.destination;
      }
    })
    return trip;
  })
  trips = result;
}

function filterTripsByTraveler(travelerID) {
  const myTrips = trips.filter(trip => trip.userID === travelerID);
  currentTraveler.sortMyTrips(myTrips);
}

function filterDestinationsBySearch(e) {
  let searchText = e.target.value.toLowerCase();
  let filteredDestinations = [];
  destinations.destinations.forEach(location => {
    if (location.destination.toLowerCase().includes(searchText)) {
      filteredDestinations.push(location)
    }
    domUpdates.displayDestinationCards(filteredDestinations);
  })
}

function checkDateInput() {
  const startDate = dateInput.value;
  const todaysDate = dayjs().format('YYYY-MM-DD');
  if (dayjs(startDate).isBefore(todaysDate)) {
    domUpdates.displayDateErrorMessage(todaysDate);
  } else {
    domUpdates.clearErrorMessage();
    return true;
  }
}

function checkNumbersInput(inputType) {
  const input = document.getElementById(inputType).value;
  const result = input.split('').map(num => parseInt(num));
  if (result.includes(NaN) || (!input)) {
    domUpdates.displayNumberErrorMessage(inputType);
  } else {
    domUpdates.clearErrorMessage();
    return true;
  }
}

function checkDestinationInput() {
  const city = document.getElementById('destinationInput').value;
  const allCities = destinations.destinations.map(location => location.destination)
  if (!allCities.includes(city)) {
    domUpdates.displayDestinationErrorMessage();
  } else {
    domUpdates.clearErrorMessage();
    return true;
  }
}

function validateFormInputs() {
  if (checkDateInput() && checkNumbersInput('durationInput') && checkNumbersInput('travelersInput') && checkDestinationInput()) {
    calculateTripEstimate();
  } else {
    domUpdates.displayTripEstimateErrorMessage();
  }
}

function calculateTripEstimate() {
  const startDate = document.getElementById('dateInput').value;
  const duration = document.getElementById('durationInput').value;
  const numTravelers = document.getElementById('travelersInput').value;
  const destination = document.getElementById('destinationInput').value;
  let locationID, estimatedLodging, estimatedFlight;
  trips.forEach(trip => {
    if (trip.destination === destination) {
      locationID = trip.destinationID;
      estimatedLodging = trip.estimatedLodgingCostPerDay;
      estimatedFlight = trip.estimatedFlightCostPerPerson;
    }
  });
  const tripData =
  {
    id: trips.length + 1,
    userID: currentTraveler.id,
    destinationID: locationID,
    travelers: parseInt(numTravelers),
    date: startDate,
    duration: parseInt(duration),
    estimatedLodgingCostPerDay: estimatedLodging,
    estimatedFlightCostPerPerson: estimatedFlight
  };
  pendingTrip = new Trip(tripData);
  const pendingTripEstimate = pendingTrip.estimateTripCost();
  if (!pendingTripEstimate) {
    domUpdates.toggleElement('.request-trip-form');
    domUpdates.displayCallUsErrorMessage();
    setResetTimer();
    domUpdates.displayDestinationCards(destinations.destinations);
  } else {
    domUpdates.displayTripEstimate(pendingTripEstimate);
    domUpdates.enableRequestButton();
  }
}

function submitNewTripRequest() {
  const tripObject = ( {id: pendingTrip.id,
    userID: pendingTrip.userID,
    destinationID: pendingTrip.destinationID,
    travelers: pendingTrip.travelers,
    date: pendingTrip.date.split('-').join('/'),
    duration: pendingTrip.duration,
    status: 'pending',
    suggestedActivities: []
  } );
  addNewTrip(tripObject)
    .then(response => {
      updatePendingTrip(pendingTrip)
      currentTraveler.addTrip('myTrips', pendingTrip)
      currentTraveler.addTrip('myPendingTrips', pendingTrip)
      trips.push(pendingTrip)
      domUpdates.displayTrips(currentTraveler)
      domUpdates.displayRequestSubmittedMessage()
    })
  setResetTimer();
  domUpdates.displayDestinationCards(destinations.destinations);
}

function updatePendingTrip(trip) {
  destinations.destinations.forEach(destination => {
    if (destination.id === trip.destinationID) {
      trip['image'] = destination.image;
      trip['alt'] = destination.alt;
      trip['destination'] = destination.destination;
    }
  });
}

function setResetTimer() {
  setTimeout(function() {domUpdates.clearForm() }, 7000);
}
<file_sep>class Trip {
  constructor(tripData) {
    this.id = tripData.id;
    this.userID = tripData.userID;
    this.destinationID = tripData.destinationID;
    this.travelers = tripData.travelers;
    this.date = tripData.date;
    this.duration = tripData.duration;
    this.status = tripData.status || 'pending';
    this.suggestedActivities = tripData.suggestedActivities || [];
    this.estimatedLodgingCostPerDay = tripData.estimatedLodgingCostPerDay;
    this.estimatedFlightCostPerPerson = tripData.estimatedFlightCostPerPerson;
  }

  estimateTripCost() {
    let totalFlightCost = this.travelers * this.estimatedFlightCostPerPerson;
    let totalLodgingCost = this.estimatedLodgingCostPerDay * this.duration;
    let totalCost = totalFlightCost + totalLodgingCost;
    let total = (totalCost * 0.1) + totalCost;
    let finalCost = Number(total).toFixed(2);
    return parseInt(finalCost);
  }
}

export default Trip;
<file_sep># Welcome to Wanderlust Excursions!

- [Description](#description)
- [Installation](#installation)
- [How To Use The Website](#how_to_use_the_website)
- [Technologies Used](#technologies_used)
- [Future Consideration](#future_considerations)
- [Contributor](#contributor)

### Description
The goal of this project was to design a user interface with accessibility in mind, while accessing and sending data from a remote API.  Object oriented programming and test driven development were utilized to ensure a properly functioning application.

### Installation
To use this application, follow these instructions:
* From your terminal, clone the repo.  
`$git clone <EMAIL>:sarahlane8/Travel-Tracker.git`  
* Move into the root directory of the project.  
* Install the required npm dependencies.  
`$npm install`
* Start the local server  
`$npm start`
* You must also clone down the Travel-Tracker API for the application to function properly. Open a separate tab in your terminal.  
`$git clone <EMAIL>:turingschool-examples/travel-tracker-api.git`
* Move into the root directory
* `$npm install`
* Start the local API server
* `$npm start`
* Open your browser [here](http://localhost:8080/) to be taken to the log in page
* You're ready to go!

### How To Use The Website

Log in to the website. All usernames begin with `traveler` followed by a number, which is the traveler's ID.  There are 50 travelers registered with the website, so any one of them may sign in.  Typing in `traveler20`, for example, will fetch Gregg's information.  All travelers have the same password of `<PASSWORD>`.  Usernames and passwords are case-sensitive, and a message will appear if the username and password do not meet the correct criteria.

<p align="center">
  <img src="https://media.giphy.com/media/3fqVJ73tvp2ErwrKXz/giphy.gif" alt="logIn demonstration"/>
</p>


The user dashboard greets the user at the top and displays their trips on the left side of the screen, separated by past trips, a current trip they may be on, upcoming trips, and any trips that are still pending an agent's approval.  It also displays how much money they have spent on trips in the last calendar year, if they have traveled during that time.  In the center, a request trip form exists so they may book future trips.  On the right, pictures of all the destinations that Wanderlust Excursions books to are available.

<p align="center">
<img height=250px; width = 500px; alt="UserDashboard" src="https://user-images.githubusercontent.com/70901622/116112002-640e2d80-a674-11eb-8bbb-89d6d3b9549d.png">
</p>

The request trip form allows a user to choose a start date, how many days they would like to go for, how many people are going, and where they would like to go.  They may start typing a location in the input field, and the destination cards on the right will filter down as they become more specific with their location, and then they may choose it from the drop down.  Clicking the estimate cost button will display how much the trip will be, including an agent's fee.
After they submit a trip request, the form will clear, and the pending trip will display on the user's dashboard.

<p align="center">
  <img src="https://media.giphy.com/media/VvTOx6yH5Yl6Mu1SqU/giphy.gif" alt="request a trip demo"/>
</p>


Several breakpoints were utilized to ensure the website would be accessible across devices.


<p align="center">
  <img src="https://media.giphy.com/media/yzeANV4boStFPKNild/giphy.gif" alt="breakpoints demonstration" />
</p>

### Technologies Used
* mocha
* chai
* Sass
* fetch API
* dayjs
* Webpack
* JavaScript

### Future Considerations
* Adding an agent login and dashboard to approve pending trips
* Allowing the trip cards to be clicked on to open up more information about that trip
* Allowing a user to upload photos associated with each trip, and notes about activities they did on teach trip

### Contributor
* <NAME> [GitHub Profile](https://github.com/sarahlane8)
* [Project Repository](https://github.com/sarahlane8/Travel-Tracker)
<file_sep>import domUpdates from './domUpdates.js';
import './scripts.js'

//************FETCHING ALL DATA************//
const fetchAllData = id => {

  const tripsData = fetch('http://localhost:3001/api/v1/trips')
    .then(response => response.json())
    .then(tripsData => {
      return tripsData;
    });

  const destinationsData = fetch('http://localhost:3001/api/v1/destinations')
    .then(response => response.json())
    .then(destinationsData => {
      return destinationsData;
    });

  const singleTravelerData = fetch(`http://localhost:3001/api/v1/travelers/${id}`)
    .then(response => response.json())
    .then(singleTravelerData => {
      return singleTravelerData;
    });

  return Promise.all([tripsData, destinationsData, singleTravelerData])
    .then(data => {
      const allData = {}
      allData.tripsData = data[0]
      allData.destinationsData = data[1]
      allData.singleTravelerData = data[2]
      return allData;
    })
    .catch(err => domUpdates.displayServerIsDownMessage());
}

//************FETCHING A SINGLE TRAVELER'S DATA************//
const fetchSingleTravelerData = id => {
  const singleTravelerData = fetch(`http://localhost:3001/api/v1/travelers/${id}`)
    .then(response => response.json())
    .then(singleTravelerData => {
      return singleTravelerData;
    })
    .catch(err => domUpdates.displayServerIsDownMessage());
};
//************FETCHING ALL TRAVELERS' DATA************//



//************ADDING A NEW TRIP FOR APPROVAL************//
const addNewTrip = tripObject => {
  return fetch('http://localhost:3001/api/v1/trips', {
    method: 'POST',
    body: JSON.stringify(tripObject),
    headers: {
      'Content-Type': 'application/json'
    }
  })
    .then(response => response.json())
    .then(response => {
      if (response.message === `Trip with id ${tripObject.id} successfully posted`) {
        return response;
      }
      if (response.message === "You are missing a required parameter of destinationID") {
        domUpdates.displayServerIsDownMessage();
      }
    })
    .catch(err => domUpdates.displayServerIsDownMessage());
}


export { fetchAllData, fetchSingleTravelerData, addNewTrip };
