diff --git a/src/amadeus/client/index.ts b/src/amadeus/client/index.ts index 8fef189..77025ce 100644 --- a/src/amadeus/client/index.ts +++ b/src/amadeus/client/index.ts @@ -8,6 +8,7 @@ import { Verb } from "../../types/amadeus/client"; import EventEmitter from "node:events"; import Listener from "./listener"; import { ReturnedResponseSuccess } from "../../types/amadeus/client/response"; +import { ResponseError } from "./errors"; /** * A convenient wrapper around the API, allowing for generic, authenticated and @@ -109,8 +110,11 @@ export default class Client implements Options { * @param {Object} [params={}] the query string parameters * @return {Promise} a Promise */ - public delete(path: string, params: object = {}): Promise { - return this.request("DELETE", path, params); + public delete( + path: string, + params: object = {} + ): Promise> { + return this.request("DELETE", path, params); } /** diff --git a/src/amadeus/namespaces/booking/flight-order.ts b/src/amadeus/namespaces/booking/flight-order.ts index 7a1ad8c..ff4ae4e 100644 --- a/src/amadeus/namespaces/booking/flight-order.ts +++ b/src/amadeus/namespaces/booking/flight-order.ts @@ -1,3 +1,8 @@ +import { ReturnedResponseSuccess } from "../../../types/amadeus/client/response"; +import { + FlightOrderGetResult, + FlightOrderGetReturenedResponse, +} from "../../../types/amadeus/namespaces/booking/flight-order"; import Client from "../../client"; /** @@ -32,10 +37,12 @@ export default class FlightOrder { * amadeus.booking.flightOrder('XXX').get(); * ``` */ - public get() { - if (this.orderId) - return this.client.get("/v1/booking/flight-orders/" + this.orderId); - throw new Error("MISSING_REQUIRED_PARAMETER"); + public get(): Promise { + if (!this.orderId) throw new Error("MISSING_REQUIRED_PARAMETER"); + + return this.client.get( + "/v1/booking/flight-orders/" + this.orderId + ); } /** @@ -49,9 +56,11 @@ export default class FlightOrder { * amadeus.booking.flightOrder('XXX').delete(); * ``` */ - public delete() { - if (this.orderId) - return this.client.delete("/v1/booking/flight-orders/" + this.orderId); - throw new Error("MISSING_REQUIRED_PARAMETER"); + public delete(): Promise> { + if (!this.orderId) throw new Error("MISSING_REQUIRED_PARAMETER"); + + return this.client.delete( + "/v1/booking/flight-orders/" + this.orderId + ); } } diff --git a/src/types/amadeus/namespaces/booking/flight-order.ts b/src/types/amadeus/namespaces/booking/flight-order.ts new file mode 100644 index 0000000..d4422cb --- /dev/null +++ b/src/types/amadeus/namespaces/booking/flight-order.ts @@ -0,0 +1,32 @@ +import { ReturnedResponseSuccess } from "../../client/response"; +import { + AssociatedRecord, + CollectionMetaLink, + Contact, + Dictionaries, + FlightOffer, + Remarks, + TicketingAgreement, + Traveler, +} from "../shared"; + +export type FlightOrderGetResult = { + meta: CollectionMetaLink; + data: { + type: "flight-order"; + id: string; + queuingOfficeId: string; + associatedRecords: AssociatedRecord; + flightOffers: FlightOffer[]; + travelers: Traveler[]; + remarks: Remarks; + ticketingAgreement: TicketingAgreement; + contacts: Contact; + }; + dictionaries: Dictionaries; +}; + +export type FlightOrderGetReturenedResponse = ReturnedResponseSuccess< + FlightOrderGetResult, + FlightOrderGetResult["data"] +>; diff --git a/src/types/amadeus/namespaces/booking/flight-orders.ts b/src/types/amadeus/namespaces/booking/flight-orders.ts index e969b59..879251b 100644 --- a/src/types/amadeus/namespaces/booking/flight-orders.ts +++ b/src/types/amadeus/namespaces/booking/flight-orders.ts @@ -1,11 +1,14 @@ import { ReturnedResponseSuccess } from "../../client/response"; import { + AssociatedRecord, CollectionMetaLink, Contact, Dictionaries, ElementaryPrice, FlightOffer, Issue, + Remarks, + TicketingAgreement, Traveler, } from "../shared"; @@ -40,18 +43,6 @@ export interface FormOfIdentification { flightOfferIds?: string[]; } -export interface TicketingAgreement { - option?: TicketingAgreementOption; - delay?: string; - dateTime?: string; - segmentIds?: string[]; -} - -export type TicketingAgreementOption = - | "CONFIRM" - | "DELAY_TO_QUEUE" - | "DELAY_TO_CANCEL"; - export interface AutomatedProcessCommon { code?: AutomatedProcessCode; queue?: { @@ -69,46 +60,6 @@ export type AutomatedProcess = AutomatedProcessCommon & { export type AutomatedProcessCode = "IMMEDIATE" | "DELAYED" | "ERROR"; -export interface Remarks { - general?: GeneralRemark[]; - airline?: AirlineRemark[]; -} - -export interface GeneralRemark { - subType: GeneralRemarkType; - category?: string; - text: string; - travelerIds?: string[]; - flightOfferIds?: string[]; -} - -export type GeneralRemarkType = - | "GENERAL_MISCELLANEOUS" - | "CONFIDENTIAL" - | "INVOICE" - | "QUALITY_CONTROL" - | "BACKOFFICE" - | "FULFILLMENT" - | "ITINERARY" - | "TICKETING_MISCELLANEOUS" - | "TOUR_CODE"; - -export interface AirlineRemark { - subType: AirlineRemarkType; - keyword?: string; - airlineCode: string; - text: string; - travelerIds?: string[]; - flightOfferIds?: string[]; -} - -export type AirlineRemarkType = - | "OTHER_SERVICE_INFORMATION" - | "KEYWORD" - | "OTHER_SERVICE" - | "CLIENT_ID" - | "ADVANCED_TICKET_TIME_LIMIT"; - export interface FormOfPayment { b2bWallet?: B2BWallet; creditCard?: CreditCard; @@ -159,16 +110,6 @@ export interface OtherMethod { export type OtherPaymentMethod = "ACCOUNT" | "CHECK" | "CASH" | "NONREFUNDABLE"; -export interface AssociatedRecordCommon { - reference?: string; - creationDate?: string; - originSystemCode?: string; -} - -export type AssociatedRecord = AssociatedRecordCommon & { - flightOfferId?: string; -}; - export type AirTravelDocument = AirTravelDocumentCommon & { travelerId?: string; segmentIds?: string[]; diff --git a/src/types/amadeus/namespaces/shared.ts b/src/types/amadeus/namespaces/shared.ts index fe73878..af5c22c 100644 --- a/src/types/amadeus/namespaces/shared.ts +++ b/src/types/amadeus/namespaces/shared.ts @@ -337,11 +337,10 @@ export type DiscountTravelerType = | "MILITARY" | "MINOR_WITHOUT_ID"; - export type Name = BaseName & { - secondLastName?: string; - }; +export type Name = BaseName & { + secondLastName?: string; +}; - export interface BaseName { firstName?: string; lastName?: string; @@ -371,26 +370,88 @@ export type ContactPurpose = | "INVOICE" | "STANDARD_WITHOUT_TRANSMISSION"; - export interface ContactDictionary { - addresseeName?: Name; - address?: Address; - language?: string; - purpose?: ContactPurpose; - } - - export interface Address { - lines?: string[]; - postalCode?: string; - countryCode?: string; - cityName?: string; - stateName?: string; - postalBox?: string; - } - - export interface Phone { - deviceType?: PhoneDeviceType; - countryCallingCode?: string; - number?: string; - } - - export type PhoneDeviceType = "MOBILE" | "LANDLINE" | "FAX"; \ No newline at end of file +export interface ContactDictionary { + addresseeName?: Name; + address?: Address; + language?: string; + purpose?: ContactPurpose; +} + +export interface Address { + lines?: string[]; + postalCode?: string; + countryCode?: string; + cityName?: string; + stateName?: string; + postalBox?: string; +} + +export interface Phone { + deviceType?: PhoneDeviceType; + countryCallingCode?: string; + number?: string; +} + +export type PhoneDeviceType = "MOBILE" | "LANDLINE" | "FAX"; + +export interface Remarks { + general?: GeneralRemark[]; + airline?: AirlineRemark[]; +} + +export interface GeneralRemark { + subType: GeneralRemarkType; + category?: string; + text: string; + travelerIds?: string[]; + flightOfferIds?: string[]; +} + +export type GeneralRemarkType = + | "GENERAL_MISCELLANEOUS" + | "CONFIDENTIAL" + | "INVOICE" + | "QUALITY_CONTROL" + | "BACKOFFICE" + | "FULFILLMENT" + | "ITINERARY" + | "TICKETING_MISCELLANEOUS" + | "TOUR_CODE"; + +export interface AirlineRemark { + subType: AirlineRemarkType; + keyword?: string; + airlineCode: string; + text: string; + travelerIds?: string[]; + flightOfferIds?: string[]; +} + +export type AirlineRemarkType = + | "OTHER_SERVICE_INFORMATION" + | "KEYWORD" + | "OTHER_SERVICE" + | "CLIENT_ID" + | "ADVANCED_TICKET_TIME_LIMIT"; + +export interface TicketingAgreement { + option?: TicketingAgreementOption; + delay?: string; + dateTime?: string; + segmentIds?: string[]; +} + +export type TicketingAgreementOption = + | "CONFIRM" + | "DELAY_TO_QUEUE" + | "DELAY_TO_CANCEL"; + +export interface AssociatedRecordCommon { + reference?: string; + creationDate?: string; + originSystemCode?: string; +} + +export type AssociatedRecord = AssociatedRecordCommon & { + flightOfferId?: string; +};