-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotelCollection.js
More file actions
51 lines (40 loc) · 1.46 KB
/
hotelCollection.js
File metadata and controls
51 lines (40 loc) · 1.46 KB
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
43
44
45
46
47
48
49
50
51
class HotelCollection{
constructor(){
this.hotels =[];
}
add(hotel, review){
var tempHotel = hotel
tempHotel.addReview(review, "")
this.hotels.push(tempHotel)
}
sortedHotels(){
this.hotels.sort((a,b)=>{
return b.averageRating - a.averageRating
});
return this.hotels;
}
removeHotel(hotelUrl){
this.hotels = this.hotels.filter(function(obj) {//once it receives the request it assigns the hotel list in the hotelCollections obj to a new list without the specified hotel
return "/hotels/"+obj.urlSlug != hotelUrl;
});
}
getHotelSpecified(hotelUrl){//we are getting a single hotel returning it as an array with one object within it being the hotel, this is because the addHotelsToPage function takes an array
let tempHotelHolder;
tempHotelHolder = this.hotels.filter(function(obj) {//once it receives the request it assigns the hotel list in the hotelCollections obj to a new list without the specified hotel
// return "/hotels/"+obj.urlSlug == hotelUrl
return obj.urlSlug == hotelUrl;
});
return tempHotelHolder
}
getReviewsOfHotel(hotelurlslug){
for(let hotel of this.hotels){
if(hotel.urlSlug == hotelurlslug){
return hotel.reviewList
}
}
}
toJSON(){
return this.hotels
}
}
module.exports = HotelCollection