import BaseEntity from '../../common/entities/BaseEntity'; import ValidableInterface from '../../common/interfaces/ValidableInterface'; import JourneyVehicle from '../../JourneyVehicle/entity/JourneyVehicle'; import Route from '../../Route/entity/Route'; import JourneyDirection from '../../common/enums/JourneyDirection'; import JourneyStop from '../../JourneyStop/entity/JourneyStop'; export default class Journey extends BaseEntity implements ValidableInterface { private _name: string; private _product_name: string; private _route: Route; private _type: JourneyDirection = null; private _journey_type: JourneyDirection = null; private _enabled: boolean = true; private _departure_date: string = null; private _arrival_date: string = null; private _seats_on_sale: number = null; private _journey_vehicles: Array = []; private _stops: Array = []; private _route_id: string; private _product_id: string; get name(): string { return this._name; } set name(value: string) { this._name = value; } get route(): Route { return this._route; } set route(value: Route) { this._route = value; } get type(): JourneyDirection { return this._type; } set type(value: JourneyDirection) { this._type = value; } get journey_type(): JourneyDirection { return this._journey_type; } set journey_type(value: JourneyDirection) { this._journey_type = value; } get enabled(): boolean { return this._enabled; } set enabled(value: boolean) { this._enabled = value; } get departure_date(): string { return this._departure_date; } set departure_date(value: string) { this._departure_date = value; } get arrival_date(): string { return this._arrival_date; } set arrival_date(value: string) { this._arrival_date = value; } get seats_on_sale(): number { return this._seats_on_sale; } set seats_on_sale(value: number) { this._seats_on_sale = value; } get journey_vehicles(): Array { return this._journey_vehicles; } set journey_vehicles(value: Array) { this._journey_vehicles = value; } get stops(): Array { return this._stops; } set stops(value: Array) { this._stops = value; } get route_id(): string { return this._route_id; } set route_id(value: string) { this._route_id = value; } get product_id(): string { return this._product_id; } set product_id(value: string) { this._product_id = value; } get product_name(): string { return this._product_name; } set product_name(value: string) { this._product_name = value; } // Custom methods :: Journey Vehicles ============================================================ setJourneyVehicle(index, item: JourneyVehicle) { this.journey_vehicles[index] = item; } removeJourneyVehicle(index) { this.journey_vehicles.splice(index, 1); } addJourneyVehicle(item: JourneyVehicle) { this.journey_vehicles.push(item); } // Custom methods :: Journey Stops =============================================================== setJourneyStop(index, item: JourneyStop) { this.stops[index] = item; } removeJourneyStop(index) { this.stops.splice(index, 1); } addJourneyStop(item: JourneyStop) { this.stops.push(item); } // Overriden ===================================================================================== isValid() { return this.invalidFields().length === 0; } invalidFields(prefix: string = '') { let fields = []; if(!this.enabled){return fields} !this.seats_on_sale && fields.push(`${prefix}seats_on_sale`); return fields; } }