import BaseEntity from '../../common/entities/BaseEntity'; import ValidableInterface from '../../common/interfaces/ValidableInterface'; import Vehicle from '../../Vehicle/entity/Vehicle'; import JourneyVehicleStop from '../../JourneyVehicleStop/entity/JourneyVehicleStop'; import Money from '../../common/entities/Money'; import Currency from '../../common/entities/Currency'; import Supplier from '../../Supplier/entity/Supplier'; import JourneyStop from '../../JourneyStop/entity/JourneyStop'; export default class JourneyVehicle extends BaseEntity implements ValidableInterface { private _vehicle: Vehicle; private _seats: number; private _journey_vehicle_stops: Array = []; private _extras_cost: Money = new Money(new Currency('GBP', 'L', 2), 0); private _extras_cost_currency: string; private _vehicle_cost: Money = new Money(new Currency('GBP', 'L', 2), 0); private _vehicle_cost_currency: string; private _supplier: Supplier; private _driver_name: string; private _driver_phone_number: string; private _driver_phone_number_prefix: string; private _supplier_id: string; // Adding the field to make second calls. get vehicle(): Vehicle { return this._vehicle; } set vehicle(value: Vehicle) { this._vehicle = value; } get seats(): number { return this._seats; } set seats(value: number) { this._seats = value; } get journey_vehicle_stops(): Array { return this._journey_vehicle_stops; } set journey_vehicle_stops(value: Array) { this._journey_vehicle_stops = value; } get extras_cost(): Money { return this._extras_cost; } set extras_cost(value: Money) { this._extras_cost = value; } get extras_cost_currency(): string { return this._extras_cost_currency; } set extras_cost_currency(value: string) { this._extras_cost_currency = value; } get vehicle_cost(): Money { return this._vehicle_cost; } set vehicle_cost(value: Money) { this._vehicle_cost = value; } get vehicle_cost_currency(): string { return this._vehicle_cost_currency; } set vehicle_cost_currency(value: string) { this._vehicle_cost_currency = value; } get supplier(): Supplier { return this._supplier; } set supplier(value: Supplier) { this._supplier = value; } get driver_name(): string { return this._driver_name; } set driver_name(value: string) { this._driver_name = value; } get driver_phone_number(): string { return this._driver_phone_number; } set driver_phone_number(value: string) { this._driver_phone_number = value; } get driver_phone_number_prefix(): string { return this._driver_phone_number_prefix; } set driver_phone_number_prefix(value: string) { this._driver_phone_number_prefix = value; } get supplier_id(): string { return this._supplier_id; } set supplier_id(value: string) { this._supplier_id = value; } // Custom methods :: Journey Vehicle Stops =============================================================== removeJourneyVehicleStop(index) { this.journey_vehicle_stops.splice(index, 1); } isValid() { return this.invalidFields().length === 0; } invalidFields() { let fields = []; !this.hasValue(this.vehicle) && fields.push('vehicle'); !this.hasValue(this.seats) && fields.push('number_of_seats'); !this.hasValue(this.journey_vehicle_stops) && fields.push('journey_vehicle_stops'); !this.hasValue(this.extras_cost) && fields.push('extra_costs'); !this.hasValue(this.extras_cost_currency) && fields.push('extra_costs_currency'); !this.hasValue(this.vehicle_cost) && fields.push('vehicle_costs'); !this.hasValue(this.vehicle_cost_currency) && fields.push('vehicle_cost_currency'); return fields; } }