Skip to content

Instantly share code, notes, and snippets.

@Nick0603
Last active March 6, 2020 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nick0603/0ca4c670a12fc8e4d7970f3c35028ce9 to your computer and use it in GitHub Desktop.
Save Nick0603/0ca4c670a12fc8e4d7970f3c35028ce9 to your computer and use it in GitHub Desktop.
"use strict";
let UserSession = require('./UserSession');
let TripDAO = require('./TripDAO');
class TripService {
getTripsByUser(user) {
let tripList = [];
let loggedUser = UserSession.getLoggedUser();
let isFriend = false;
if (loggedUser != null) {
let friends = user.getFriends();
for (let i=0; i < friends.length; i++) {
let friend = friends[i];
if (friend == loggedUser) {
isFriend = true;
break;
}
};
if (isFriend) {
tripList = TripDAO.findTripsByUser(user);
}
return tripList;
} else {
throw new Error('User not logged in.');
}
}
}
module.exports = TripService
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment