Skip to content

Commit

Permalink
types: added flight choice prediction types
Browse files Browse the repository at this point in the history
  • Loading branch information
darseen committed Aug 17, 2024
1 parent 9d563d6 commit dd0f28b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
FlightOffersPredictionParams,
FlightOffersPredictionResult,
FlightOffersPredictionReturnedResponse,
} from "../../../../types/amadeus/namespaces/shopping/flight-offers/flight-choice-prediction";
import Client from "../../../client";

/**
Expand Down Expand Up @@ -36,7 +41,7 @@ export default class FlightChoicePrediction {
* adults: '2'
* }).then(function(response){
* return amadeus.shopping.flightOffers.prediction.post(
* JSON.stringify(response)
* response
* );
* }).then(function(response){
* console.log(response.data);
Expand All @@ -45,7 +50,12 @@ export default class FlightChoicePrediction {
* });
* ```
*/
public post(params: Object = {}) {
return this.client.post("/v2/shopping/flight-offers/prediction", params);
public post(
params: FlightOffersPredictionParams
): Promise<FlightOffersPredictionReturnedResponse> {
return this.client.post<
FlightOffersPredictionResult,
FlightOffersPredictionResult["data"]
>("/v2/shopping/flight-offers/prediction", JSON.stringify(params));
}
}
29 changes: 17 additions & 12 deletions src/types/amadeus/namespaces/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@ export interface Issue {

export interface CollectionMeta {
count?: number;
oneWayCombinations?: {
originDestinationId?: string;
flightOfferIds?: string[];
}[];
oneWayCombinations?: OneWayCombinations;
}

export type OneWayCombinations = {
originDestinationId?: string;
flightOfferIds?: string[];
}[];

export interface CollectionMetaLink {
count?: number;
links?: {
self?: string;
next?: string;
previous?: string;
last?: string;
first?: string;
up?: string;
};
links?: CollectionLinks;
}

export interface CollectionLinks {
self?: string;
next?: string;
previous?: string;
last?: string;
first?: string;
up?: string;
}

export interface LocationValue {
Expand Down Expand Up @@ -223,6 +227,7 @@ export interface FlightOffer {
};
}[];
}[];
fareRules?: FareRules;
}

export type Segment = {
Expand Down
8 changes: 4 additions & 4 deletions src/types/amadeus/namespaces/shopping/flight-offers-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ export type FlightOffersSearchPostParams = {
};

export type FlightOffersSearchPostResult = {
meta: CollectionMeta;
meta?: CollectionMeta;
warnings?: Issue[];
data: FlightOffer[];
dictionaries: Dictionaries;
dictionaries?: Dictionaries;
};

export type FlightOffersSearchGetParams = {
Expand All @@ -146,10 +146,10 @@ export type FlightOffersSearchGetParams = {
};

export type FlightOffersSearchGetResult = {
meta: CollectionMetaLink;
meta?: CollectionMetaLink;
warnings?: Issue[];
data: FlightOffer[];
dictionaries: Dictionaries;
dictionaries?: Dictionaries;
};

export type FlightOffersSearchGetReturnedResponse = Promise<
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ReturnedResponseSuccess } from "../../../client/response";
import {
CollectionMetaLink,
OneWayCombinations,
Dictionaries,
FlightOffer,
Issue,
} from "../../shared";
import { FlightOffersSearchGetResult } from "../flight-offers-search";

// Types used in class
export type FlightOffersPredictionParams = FlightOffersSearchGetResult;

export type FlightOffersPredictionResult = {
warnings?: Issue[];
meta?: CollectionMetaLink & {
oneWayCombinations?: OneWayCombinations;
};
data: FlightOffer[];
dictionaries?: Dictionaries;
};

export type FlightOffersPredictionReturnedResponse = ReturnedResponseSuccess<
FlightOffersPredictionResult,
FlightOffersPredictionResult["data"]
>;
55 changes: 1 addition & 54 deletions src/types/amadeus/namespaces/shopping/seatmaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FareRules,
Fee,
FlightEndPoint,
FlightOffer,
FlightOfferSource,
Issue,
LocationEntry,
Expand All @@ -27,60 +28,6 @@ export interface OperatingFlight {
suffix?: string;
}

export interface FlightOffer {
type: string;
id: string;
source?: FlightOfferSource;
instantTicketingRequired?: boolean;
disablePricing?: boolean;
nonHomogeneous?: boolean;
oneWay?: boolean;
paymentCardRequired?: boolean;
lastTicketingDate?: string;
numberOfBookableSeats?: number;
itineraries?: {
duration?: string;
segments: Segment[];
}[];
price?: ExtendedPrice;
pricingOptions?: {
fareType?: PricingOptionsFareType;
corporateCodes?: string[];
includedCheckedBagsOnly?: boolean;
refundableFare?: boolean;
noRestrictionFare?: boolean;
noPenaltyFare?: boolean;
};
validatingAirlineCodes?: string[];
travelerPricings?: {
travelerId: string;
fareOption: TravelerPricingFareOption;
travelerType: TravelerType;
associatedAdultId?: string;
price?: Price;
fareDetailsBySegment: {
segmentId: string;
cabin?: TravelClass;
fareBasis?: string;
brandedFare?: string;
class?: string;
isAllotment?: boolean;
allotmentDetails?: {
tourName?: string;
tourReference?: string;
};
sliceDiceIndicator?: SliceDiceIndicator;
includedCheckedBags?: BaggageAllowance;
additionalServices?: {
chargeableCheckedBags?: BaggageAllowance;
chargeableSeatNumber?: string;
otherServices?: ServiceName[];
};
}[];
}[];
fareRules?: FareRules;
}

export interface BaggageAllowance {
excessRate?: ElementaryPrice;
quantity?: number;
Expand Down
4 changes: 2 additions & 2 deletions tests/amadeus/namespaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ describe("Namespaces", () => {

it(".amadeus.shopping.flightOffers.prediction.post", () => {
amadeus["client"].post = vi.fn();
amadeus.shopping.flightOffers.prediction.post();
amadeus.shopping.flightOffers.prediction.post({} as any);
expect(amadeus["client"].post).toHaveBeenCalledWith(
"/v2/shopping/flight-offers/prediction",
{}
JSON.stringify({})
);
});

Expand Down

0 comments on commit dd0f28b

Please sign in to comment.