Skip to content

Commit

Permalink
types: added flight order get & delete types
Browse files Browse the repository at this point in the history
  • Loading branch information
darseen committed Aug 13, 2024
1 parent f10d397 commit d640c9a
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 99 deletions.
8 changes: 6 additions & 2 deletions src/amadeus/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,8 +110,11 @@ export default class Client implements Options {
* @param {Object} [params={}] the query string parameters
* @return {Promise<Response|ResponseError>} a Promise
*/
public delete(path: string, params: object = {}): Promise<unknown> {
return this.request("DELETE", path, params);
public delete<T, K>(
path: string,
params: object = {}
): Promise<ReturnedResponseSuccess<T, K>> {
return this.request<T, K>("DELETE", path, params);
}

/**
Expand Down
25 changes: 17 additions & 8 deletions src/amadeus/namespaces/booking/flight-order.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down Expand Up @@ -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<FlightOrderGetReturenedResponse> {
if (!this.orderId) throw new Error("MISSING_REQUIRED_PARAMETER");

return this.client.get<FlightOrderGetResult, FlightOrderGetResult["data"]>(
"/v1/booking/flight-orders/" + this.orderId
);
}

/**
Expand All @@ -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<ReturnedResponseSuccess<null, null>> {
if (!this.orderId) throw new Error("MISSING_REQUIRED_PARAMETER");

return this.client.delete<null, null>(
"/v1/booking/flight-orders/" + this.orderId
);
}
}
32 changes: 32 additions & 0 deletions src/types/amadeus/namespaces/booking/flight-order.ts
Original file line number Diff line number Diff line change
@@ -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"]
>;
65 changes: 3 additions & 62 deletions src/types/amadeus/namespaces/booking/flight-orders.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ReturnedResponseSuccess } from "../../client/response";
import {
AssociatedRecord,
CollectionMetaLink,
Contact,
Dictionaries,
ElementaryPrice,
FlightOffer,
Issue,
Remarks,
TicketingAgreement,
Traveler,
} from "../shared";

Expand Down Expand Up @@ -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?: {
Expand All @@ -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;
Expand Down Expand Up @@ -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[];
Expand Down
115 changes: 88 additions & 27 deletions src/types/amadeus/namespaces/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
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;
};

0 comments on commit d640c9a

Please sign in to comment.