Users:
{"id":1, "name":"Leatha Ullrich"}
Rooms:
{"number":1, "roomType":"residential suite", "bidet":true, "bedSize":"queen", "numBeds":1, "costPerNight":358.4}
Bookings:
{"id":"5fwrgu4i7k55hl6t5", "userID":43, "date":"2020/01/24", "roomNumber":24, "roomServiceCharges":[]}
-
Hotel
class Hotel { constructor(userData, roomData) { this.user = null, this.roomRecord = new RoomRecord(roomData), this.guestDirectory = new GuestDirectory(userData), this.userService = new Service(/*api url*/, 'userData'), this.roomService = new Service(/*api url*/, 'roomData'), this.bookingService = new Service(/*api url*/, 'bookingData') } chooseUser(username, password) { if... new Manager() else... new Guest(username) } }
-
User
class User { constructor(userData, username, password) { this.username = username, this.password = password, this.bookingRecord = new BookingRecord(bookingData) } }
-
Manager
class Manager extends User { constructor() { super() } calculateDailyRevenue(date) { } }
-
Guest
class Guest extends User { constructor(user) { super() this.id = user.id, this.name = user.name, this.currentBookings = [], this.previousBookings = [] } bookRoom(date) { } deleteBooking(date) { } }
-
GuestDirectory
class GuestDirectory { constructor(userData) { this.rawUserData = userData, this.guestDirectory = [] } createGuestDirectory() { } searchGuests(input) { } }
-
Room
class Room { constructor(room) { this.number = room.number, this.roomType = room.roomType, this.bidet = room.bidet, this.bedSize = room.bedSize, this.numBeds = room.numBeds, this.costPerNight = room.costPerNight } }
-
RoomRecord
class RoomRecord { constructor(roomsData) { this.rawRoomsData = roomsData, this.roomsRecord = [], this.roomService = new Service(/*api url*/) } createRoomRecord() { } showAvailableRooms(date) { } }
-
Booking
class Booking { constructor(booking) { this.id = booking.id, this.userID = booking.userID, this.date = booking.date, this.roomNumber = booking.date, this.roomServiceCharges = [] } }
-
BookingRecord
class BookingRecord { constructor(bookingsData) { this.rawBookingsData = bookingsData, this.bookingsRecord = [] this.currentBookings = [] } createBookingsRecord() { } }
-
Service - API's
class Service { constructor(url, dataKey) { this.url = url, this.dataKey = dataKey } getRequest() { return fetch(this.url) .then(response => response.json()) .then(data => data[this.dataKey]) .catch(err => console.log(err)) } postRequest(newPost, onSuccess) { return fetch(this.url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(newPost) }) .then(response => response.json()) .then(json => { console.log(json); onSuccess(); }) .catch(err => console.log(err)) } deleteRequest() { } }