-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDestination.js
42 lines (36 loc) · 1.23 KB
/
Destination.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Destination {
constructor(destinationData) {
this.destinations = destinationData;
this.userDestinations;
}
findById(id) {
return this.destinations.find(destination => destination.id === id)
}
findByTrips(trips) {
const userDestinationIds = trips.map(trip => trip["destinationID"])
this.userDestinations = this.destinations.filter(destination => userDestinationIds.includes(destination["id"]))
return this.userDestinations;
}
findId(destinationName) {
const id = this.destinations.find(destination => destination.destination === destinationName).id;
return id;
}
findTotalSpent(trips) {
const total = trips.reduce((sum, trip) => {
let lodgingSum = 0;
let flightSum = 0;
sum += lodgingSum + flightSum;
this.destinations.forEach(destination => {
if (destination["id"] === trip["destinationID"]) {
lodgingSum = destination["estimatedLodgingCostPerDay"] * trip["duration"];
flightSum = destination["estimatedFlightCostPerPerson"] * trip["travelers"];
return sum = lodgingSum + flightSum;
}
})
return sum;
}, 0)
const agentFee = total + total * .1;
return agentFee;
}
};
module.exports = Destination;