import BookingAdapterInterface from './BookingAdapterInterface'; import Booking from '../entity/Booking'; import JourneyAdapterInterface from '../../Journey/adapter/JourneyAdapterInterface'; import StopAdapterInterface from '../../Stop/adapter/StopAdapterInterface'; import PassengerTypeAdapterInterface from '../../PassengerType/adapter/PassengerTypeAdapterInterface'; import EventProductAdapterInterface from '../../EventProduct/adapter/EventProductAdapterInterface'; export default class BookingAdapter implements BookingAdapterInterface { protected journeyAdapter: JourneyAdapterInterface; protected eventProductAdapter: EventProductAdapterInterface; protected stopAdapter: StopAdapterInterface; protected passengerTypeAdapter: PassengerTypeAdapterInterface; constructor(journeyAdapter: JourneyAdapterInterface, eventProductAdapter: EventProductAdapterInterface, stopAdapter: StopAdapterInterface, passengerTypeAdapter: PassengerTypeAdapterInterface) { this.journeyAdapter = journeyAdapter; this.eventProductAdapter = eventProductAdapter; this.stopAdapter = stopAdapter; this.passengerTypeAdapter = passengerTypeAdapter; } adapt(json: any, instance: Booking): Booking { instance.id = json.id; instance.journey = this.journeyAdapter.transformToEntity(json.journey); instance.event_product = this.eventProductAdapter.transformToEntity(json.event_product); instance.date = json.date; instance.legs = json.legs.map(each => { let object = { pickup: this.stopAdapter.transformToEntity(each.pickup), dropoff: this.stopAdapter.transformToEntity(each.dropoff), }; return object; }); instance.original_price = json.original_price; instance.paid_amount= json.paid_amount; instance.number_of_passengers = json.concessions.map(each => { let object = { passenger_type: this.passengerTypeAdapter.transformToEntity(each.passenger_type), number_of_seats: each.number_of_seats, }; return object; }); return instance; } prepare(instance: Booking): object { throw new Error('Bookings cannot be prepared.'); } transformToEntity(json: any): Booking { return this.adapt(json, new Booking()); } transformToPayload(instance: Booking): any { return this.prepare(instance); } }