Reference Source
import HotelManager from 'wt-js-libs/libs/HotelManager.js'
public class | source

HotelManager

Methods that allow a manager to create / administrate hotels

Example:

  const hotel = new HotelManager({
    indexAddress: '0x75a3...b', // Address of the WTIndex contract that lists this hotel
    owner: '0xab3...cd',        // Payer of lib tx fees, registered as owner the WTIndex
    web3: web3,                 // Instantiated web3 object with its provider set.
  });

Constructor Summary

Public Constructor
public

Instantiates a HotelManager with a web3 object, an owner account address, and the address of the Index contract that has registered hotel assets.

Member Summary

Public Members
public

WTIndex: *

public

context: *

public

hotels: *

public
public

owner: *

public

web3: *

Method Summary

Public Methods
public

async addAmenity(hotelAddress: Address, unitType: String, amenity: Number): Promievent

Adds an amenity to a unit type

public

async addImageHotel(hotelAddress: Address, url: String): Promievent

Adds an image to a hotel

public

async addImageUnitType(hotelAddress: Address, unitType: String, url: String): Promievent

Adds an image to a unit type

public

async addUnit(hotelAddress: Address, unitType: String): Promievent

Deploys a Unit contract and registers it to an existing Hotel contract

public

async addUnitType(hotelAddress: Address, unitType: String): Promievent

Deploys a UnitType contract and registers it to an existing Hotel contract

public

async changeHotelAddress(hotelAddress: Address, lineOne: String, lineTwo: String, zipCode: String, country: String): Promievent

Edits a hotel's physical address data.

public

async changeHotelInfo(hotelAddress: Address, name: String, description: String): Promievent

Edits a hotel's name and description.

public

async changeHotelLocation(hotelAddress: Address, timezone: Number, latitude: Number, longitude: Number): Promievent

Edits a hotel's coordinate location and timezone data.

public

async confirmBooking(hotelAddress: Address, reservationId: String): Promievent

Confirms a pending booking request.

public

async createHotel(name: String, description: String): Promievent

Creates a Hotel contract instance and registers it with the HotelManager's WTIndex contract

public

async editUnitType(hotelAddress: Address, unitType: String, description: String, minGuests: Number, maxGuests: Number, price: String): Promievent

Edits a unit type's basic info data.

public

getCachedHotel(hotelAddress: *): Object

Gets the hotel data previously retrieved by a getHotel call

public

Gets hotel data previously retrieved by a getHotels call (see above)

public

Gets the contract addresses of all hotels previously retrieved by a getHotels call

public

async getHotel(hotelAddress: Address): Object

Gets non-bookings data for a Hotel contract (e.g info about its location, unit types and units).

public

async getHotels(): Object

Gets non-bookings data for all the hotels managed by the HotelManager (e.g info about their location, unit types and units).

public

async getReservation(unitAddress: Address, day: Date | Number): Promievent

Gets a unit's reservation data for a specific UTC day or date.

public

async removeAmenity(hotelAddress: Address, unitType: String, amenity: Number): Promievent

Removes an amenity from a unit type.

public

async removeHotel(address: Address): Promievent

Removes a hotel from the WTIndex registry

public

async removeImageHotel(hotelAddress: Address, imageIndex: Number): Promievent

Removes an image from a hotel

public

async removeImageUnitType(hotelAddress: Address, unitType: String, imageIndex: Number): Promievent

Removes an image to a unit type

public

async removeUnit(hotelAddress: Address, unitAddress: Address): Promievent

Unregisters a Unit contract from an existing Hotel contract

public

async removeUnitType(hotelAddress: Address, unitType: String): Promievent

Unregisters a UnitType contract from an existing Hotel contract

public

async setCurrencyCode(hotelAddress: Address, unitAddress: Address, code: Number, converter: Function, convertStart: Date, convertEnd: Date): Promievent

Changes the default currency code

public

async setDefaultLifPrice(hotelAddress: Address, unitAddress: Address, price: String | Number | BN): Promievent

Sets the default LifPrice for this unit

public

async setDefaultPrice(hotelAddress: Address, unitAddress: Address, price: Number): Promievent

Sets the default price for a unit

public

async setRequireConfirmation(hotelAddress: Address, value: Boolean): *

Sets a boolean flag in a Hotel contract that determines whether bookings can happen instantly or require confirmation by a manager before they proceed.

public

async setUnitActive(hotelAddress: Address, unitAddress: Address, active: Boolean): *

Sets a Unit contracts active status.

public

async setUnitSpecialLifPrice(hotelAddress: Address, unitAddress: Address, price: String | Number | BN, fromDate: Date, amountDays: Number): Promievent

Sets a unit's booking price for range of days. Check-in is on the first day, check-out on the last.

public

async setUnitSpecialPrice(hotelAddress: Address, unitAddress: Addres, price: Number, fromDate: Date, amountDays: Number): Promievent

Sets a unit's national currency booking price for range of days. Check-in is on the first day, check-out on the last.

public

setWeb3(_web3: Object)

Sets the Hotel class's web3 instance.

Public Constructors

public constructor(options: Object): HotelManager source

Instantiates a HotelManager with a web3 object, an owner account address, and the address of the Index contract that has registered hotel assets.

Params:

NameTypeAttributeDescription
options Object

(see example above)

Return:

HotelManager

Public Members

public WTIndex: * source

public context: * source

public hotels: * source

public hotelsAddrs: *[] source

public owner: * source

public web3: * source

Public Methods

public async addAmenity(hotelAddress: Address, unitType: String, amenity: Number): Promievent source

Adds an amenity to a unit type

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the UnitType contract to edit

unitType String

unique plain text id of UnitType, ex: 'BASIC_ROOM'

amenity Number

integer code of amenity to add: ex: 23

Return:

Promievent

public async addImageHotel(hotelAddress: Address, url: String): Promievent source

Adds an image to a hotel

Params:

NameTypeAttributeDescription
hotelAddress Address

contract address

url String

url of the image to add

Return:

Promievent

public async addImageUnitType(hotelAddress: Address, unitType: String, url: String): Promievent source

Adds an image to a unit type

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the UnitType contract to edit

unitType String

unique plain text id of UnitType, ex: 'BASIC_ROOM'

url String

url of the image to add

Return:

Promievent

public async addUnit(hotelAddress: Address, unitType: String): Promievent source

Deploys a Unit contract and registers it to an existing Hotel contract

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that will control created Unit contract

unitType String

unique plain text id of this units UnitType, ex: 'BASIC_ROOM'

Return:

Promievent

public async addUnitType(hotelAddress: Address, unitType: String): Promievent source

Deploys a UnitType contract and registers it to an existing Hotel contract

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that will control created UnitType contract

unitType String

unique plain text id of UnitType, ex: 'BASIC_ROOM'

Return:

Promievent

public async changeHotelAddress(hotelAddress: Address, lineOne: String, lineTwo: String, zipCode: String, country: String): Promievent source

Edits a hotel's physical address data.

Params:

NameTypeAttributeDescription
hotelAddress Address

contract address

lineOne String

physical address data

lineTwo String

physical address data

zipCode String

physical address data

country String

physical address data

Return:

Promievent

public async changeHotelInfo(hotelAddress: Address, name: String, description: String): Promievent source

Edits a hotel's name and description.

Params:

NameTypeAttributeDescription
hotelAddress Address

contract address

name String

hotel name

description String

hotel description

Return:

Promievent

public async changeHotelLocation(hotelAddress: Address, timezone: Number, latitude: Number, longitude: Number): Promievent source

Edits a hotel's coordinate location and timezone data.

Params:

NameTypeAttributeDescription
hotelAddress Address

contract address

timezone Number

positive integer timezone relative to GMT

latitude Number

GPS latitude location data e.g -3.703578

longitude Number

GPS longitude location data e.g 40.426371

Return:

Promievent

public async confirmBooking(hotelAddress: Address, reservationId: String): Promievent source

Confirms a pending booking request. reservationId is the value of the dataHash field from the CallStarted event fired when a booking that requires confirmation is initiated.

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract address that controls unit requested

reservationId String

data hash.

Return:

Promievent

public async createHotel(name: String, description: String): Promievent source

Creates a Hotel contract instance and registers it with the HotelManager's WTIndex contract

Params:

NameTypeAttributeDescription
name String

name

description String

description

Return:

Promievent

public async editUnitType(hotelAddress: Address, unitType: String, description: String, minGuests: Number, maxGuests: Number, price: String): Promievent source

Edits a unit type's basic info data.

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the UnitType contract to edit

unitType String

unique plain text id of UnitType, ex: 'BASIC_ROOM'

description String

description: e.g. 'Simple. Clean.'

minGuests Number

minimum number of guests that can stay in UnitType

maxGuests Number

maximum number of guests that can stay in UnitType

price String

price of UnitType: e.g '50 euros'

Return:

Promievent

public getCachedHotel(hotelAddress: *): Object source

Gets the hotel data previously retrieved by a getHotel call

Params:

NameTypeAttributeDescription
hotelAddress *

Return:

Object

Example:

  (we should have a doc link to JSON output here)

public getCachedHotels(): Object source

Gets hotel data previously retrieved by a getHotels call (see above)

Return:

Object

Example:

  (we should have a doc link to JSON output here)

public getCachedHotelsAddrs(): Array source

Gets the contract addresses of all hotels previously retrieved by a getHotels call

Return:

Array

Example:

 const [Hotel1, Hotel2] = lib.getHotelsAddrs();

public async getHotel(hotelAddress: Address): Object source

Gets non-bookings data for a Hotel contract (e.g info about its location, unit types and units).

Params:

NameTypeAttributeDescription
hotelAddress Address

address of Hotel contract

Return:

Object

Example:

 (we should have a doc link to JSON output here)

public async getHotels(): Object source

Gets non-bookings data for all the hotels managed by the HotelManager (e.g info about their location, unit types and units).

Return:

Object

Example:

(we should have a doc link to JSON output here)

public async getReservation(unitAddress: Address, day: Date | Number): Promievent source

Gets a unit's reservation data for a specific UTC day or date.

Params:

NameTypeAttributeDescription
unitAddress Address

contract address of Unit

day Date | Number

Date | UTC day since 1970

Return:

Promievent

Example:

  const {
    specialPrice,    // Price: 200.00
    specialLifPrice, // LifPrice (ether): 20
    bookedBy         // Address: e.g. '0x39a...2b'
  } = await lib.getReservation('0xab3..cd', new Date('5/31/2020'));

public async removeAmenity(hotelAddress: Address, unitType: String, amenity: Number): Promievent source

Removes an amenity from a unit type.

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the UnitType contract to edit

unitType String

unique plain text id of UnitType, ex: 'BASIC_ROOM'

amenity Number

integer code of amenity to remove: ex: 23

Return:

Promievent

public async removeHotel(address: Address): Promievent source

Removes a hotel from the WTIndex registry

Params:

NameTypeAttributeDescription
address Address

address of Hotel contract to de-list

Return:

Promievent

public async removeImageHotel(hotelAddress: Address, imageIndex: Number): Promievent source

Removes an image from a hotel

Params:

NameTypeAttributeDescription
hotelAddress Address

contract address

imageIndex Number

index of the image to remove

Return:

Promievent

public async removeImageUnitType(hotelAddress: Address, unitType: String, imageIndex: Number): Promievent source

Removes an image to a unit type

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the UnitType contract to edit

unitType String

unique plain text id of UnitType, ex: 'BASIC_ROOM'

imageIndex Number

index of the image to remove

Return:

Promievent

public async removeUnit(hotelAddress: Address, unitAddress: Address): Promievent source

Unregisters a Unit contract from an existing Hotel contract

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the Unit contract to remove

unitAddress Address

Unit contract to remove

Return:

Promievent

public async removeUnitType(hotelAddress: Address, unitType: String): Promievent source

Unregisters a UnitType contract from an existing Hotel contract

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the UnitType contract to remove

unitType String

unique plain text id of UnitType, ex: 'BASIC_ROOM'

Return:

Promievent

public async setCurrencyCode(hotelAddress: Address, unitAddress: Address, code: Number, converter: Function, convertStart: Date, convertEnd: Date): Promievent source

Changes the default currency code

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the Unit being edited

unitAddress Address

Unit contract to edit

code Number

Integer currency code btw 0 and 255

converter Function

ex euro = kroneToEuro(krone)

convertStart Date

date to begin search of specialPrices

convertEnd Date

date (inclusive) to end search of specialPrices

Return:

Promievent

public async setDefaultLifPrice(hotelAddress: Address, unitAddress: Address, price: String | Number | BN): Promievent source

Sets the default LifPrice for this unit

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the Unit contract to edit

unitAddress Address

Unit contract to edit

price String | Number | BN

Lif 'ether' (converted to wei by web3.utils.toWei)

Return:

Promievent

public async setDefaultPrice(hotelAddress: Address, unitAddress: Address, price: Number): Promievent source

Sets the default price for a unit

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the Unit being edited

unitAddress Address

Unit contract to edit

price Number

Integer or floating point price

Return:

Promievent

public async setRequireConfirmation(hotelAddress: Address, value: Boolean): * source

Sets a boolean flag in a Hotel contract that determines whether bookings can happen instantly or require confirmation by a manager before they proceed.

Params:

NameTypeAttributeDescription
hotelAddress Address

Contract address of the hotel to edit.

value Boolean

t/f: require confirmation

Return:

*

public async setUnitActive(hotelAddress: Address, unitAddress: Address, active: Boolean): * source

Sets a Unit contracts active status. This determines whether or not it can be booked.

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the Unit contract to edit

unitAddress Address

Unit contract to edit

active Boolean

Unit is locked when false.

Return:

*

public async setUnitSpecialLifPrice(hotelAddress: Address, unitAddress: Address, price: String | Number | BN, fromDate: Date, amountDays: Number): Promievent source

Sets a unit's booking price for range of days. Check-in is on the first day, check-out on the last.

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the Unit contract to edit

unitAddress Address

Unit contract to edit

price String | Number | BN

Lif 'ether' (converted to wei by web3.utils.toWei)

fromDate Date

check-in date

amountDays Number

integer number of days to book.

Return:

Promievent

public async setUnitSpecialPrice(hotelAddress: Address, unitAddress: Addres, price: Number, fromDate: Date, amountDays: Number): Promievent source

Sets a unit's national currency booking price for range of days. Check-in is on the first day, check-out on the last.

Params:

NameTypeAttributeDescription
hotelAddress Address

Hotel contract that controls the Unit contract to edit

unitAddress Addres

Unit contract to edit

price Number

integer or floating point price

fromDate Date

check-in date

amountDays Number

integer number of days to book.

Return:

Promievent

public setWeb3(_web3: Object) source

Sets the Hotel class's web3 instance.

Params:

NameTypeAttributeDescription
_web3 Object

Web3 instance, already instantiated with a provider