From 9d563d63d7da8457aa69685074b467404b1d778a Mon Sep 17 00:00:00 2001 From: darseen Date: Sat, 17 Aug 2024 16:29:32 +0300 Subject: [PATCH] types: added itinerary price metrics types --- src/amadeus/namespaces/analytics/index.ts | 2 +- ...-metrics.ts => itinerary-price-metrics.ts} | 14 ++++++- .../analytics/itinerary-price-metrics.ts | 40 +++++++++++++++++++ src/types/amadeus/namespaces/shared.ts | 37 ++++++++++++++++- .../shopping/flight-offers-search.ts | 5 ++- .../shopping/flight-offers/upselling.ts | 1 + tests/amadeus/namespaces.test.ts | 2 +- 7 files changed, 94 insertions(+), 7 deletions(-) rename src/amadeus/namespaces/analytics/{itenrary-price-metrics.ts => itinerary-price-metrics.ts} (72%) create mode 100644 src/types/amadeus/namespaces/analytics/itinerary-price-metrics.ts diff --git a/src/amadeus/namespaces/analytics/index.ts b/src/amadeus/namespaces/analytics/index.ts index c453b8e..5c76bc6 100644 --- a/src/amadeus/namespaces/analytics/index.ts +++ b/src/amadeus/namespaces/analytics/index.ts @@ -1,5 +1,5 @@ import Client from "../../client"; -import ItineraryPriceMetrics from "./itenrary-price-metrics"; +import ItineraryPriceMetrics from "./itinerary-price-metrics"; /** * A namespaced client for the diff --git a/src/amadeus/namespaces/analytics/itenrary-price-metrics.ts b/src/amadeus/namespaces/analytics/itinerary-price-metrics.ts similarity index 72% rename from src/amadeus/namespaces/analytics/itenrary-price-metrics.ts rename to src/amadeus/namespaces/analytics/itinerary-price-metrics.ts index 29c9949..e68055d 100644 --- a/src/amadeus/namespaces/analytics/itenrary-price-metrics.ts +++ b/src/amadeus/namespaces/analytics/itinerary-price-metrics.ts @@ -1,3 +1,8 @@ +import { + ItineraryPriceMetricsParams, + ItineraryPriceMetricsResult, + ItineraryPriceMetricsReturnedResponse, +} from "../../../types/amadeus/namespaces/analytics/itinerary-price-metrics"; import Client from "../../client"; /** @@ -37,7 +42,12 @@ export default class ItineraryPriceMetrics { * }); * ``` */ - public get(params = {}) { - return this.client.get("/v1/analytics/itinerary-price-metrics", params); + public get( + params: ItineraryPriceMetricsParams + ): Promise { + return this.client.get< + ItineraryPriceMetricsResult, + ItineraryPriceMetricsResult["data"] + >("/v1/analytics/itinerary-price-metrics", params); } } diff --git a/src/types/amadeus/namespaces/analytics/itinerary-price-metrics.ts b/src/types/amadeus/namespaces/analytics/itinerary-price-metrics.ts new file mode 100644 index 0000000..3e6af4e --- /dev/null +++ b/src/types/amadeus/namespaces/analytics/itinerary-price-metrics.ts @@ -0,0 +1,40 @@ +import { ReturnedResponseSuccess } from "../../client/response"; +import { CollectionMetaLink, CurrencyCode, Issue } from "../shared"; + +export interface ItineraryPriceMetric { + type?: string; + origin?: { + iataCode?: string; + }; + destination?: { + iataCode?: string; + }; + departureDate?: string; + transportType?: "FLIGHT"; + currencyCode?: CurrencyCode; + oneWay?: boolean; + priceMetrics?: { + amount?: string; + quartileRanking?: "MINIMUM" | "FIRST" | "MEDIUM" | "THIRD" | "MAXIMUM"; + }[]; +} + +// Types used in class +export type ItineraryPriceMetricsParams = { + originIataCode: string; + destinationIataCode: string; + departureDate: string; + currencyCode?: CurrencyCode; + oneWay?: boolean; +}; + +export type ItineraryPriceMetricsResult = { + warnings?: Issue[]; + data: ItineraryPriceMetric[]; + meta?: CollectionMetaLink; +}; + +export type ItineraryPriceMetricsReturnedResponse = ReturnedResponseSuccess< + ItineraryPriceMetricsResult, + ItineraryPriceMetricsResult["data"] +>; diff --git a/src/types/amadeus/namespaces/shared.ts b/src/types/amadeus/namespaces/shared.ts index c79c5df..2473089 100644 --- a/src/types/amadeus/namespaces/shared.ts +++ b/src/types/amadeus/namespaces/shared.ts @@ -94,6 +94,41 @@ export interface OperatingFlight { carrierCode?: string; } +export type CurrencyCode = + | "CAD" + | "HKD" + | "ISK" + | "PHP" + | "DKK" + | "HUF" + | "CZK" + | "AUD" + | "RON" + | "SEK" + | "IDR" + | "INR" + | "BRL" + | "RUB" + | "HRK" + | "JPY" + | "THB" + | "EUR" + | "CHF" + | "SGD" + | "PLN" + | "BGN" + | "TRY" + | "CNY" + | "NOK" + | "NZD" + | "ZAR" + | "USD" + | "MXN" + | "ILS" + | "GBP" + | "KRW" + | "MYR"; + export interface Price { currency?: string; total?: string; @@ -346,7 +381,7 @@ export interface BaseName { export interface ElementaryPrice { amount?: string; - currencyCode?: string; + currencyCode?: CurrencyCode; } export type Traveler = Stakeholder & { diff --git a/src/types/amadeus/namespaces/shopping/flight-offers-search.ts b/src/types/amadeus/namespaces/shopping/flight-offers-search.ts index 7f35346..fffde23 100644 --- a/src/types/amadeus/namespaces/shopping/flight-offers-search.ts +++ b/src/types/amadeus/namespaces/shopping/flight-offers-search.ts @@ -2,6 +2,7 @@ import { ReturnedResponseSuccess } from "../../client/response"; import { CollectionMeta, CollectionMetaLink, + CurrencyCode, Dictionaries, FlightOffer, FlightOfferSource, @@ -113,7 +114,7 @@ export type Coverage = // Types used in class export type FlightOffersSearchPostParams = { - currencyCode?: string; + currencyCode?: CurrencyCode; originDestinations: OriginDestination[]; travelers: ExtendedTravelerInfo[]; sources: FlightOfferSource[]; @@ -139,7 +140,7 @@ export type FlightOffersSearchGetParams = { includedAirlineCodes?: string; excludedAirlineCodes?: string; nonStop?: boolean; - currencyCode?: string; + currencyCode?: CurrencyCode; maxPrice?: number; max?: number; }; diff --git a/src/types/amadeus/namespaces/shopping/flight-offers/upselling.ts b/src/types/amadeus/namespaces/shopping/flight-offers/upselling.ts index 90bd804..c16aef3 100644 --- a/src/types/amadeus/namespaces/shopping/flight-offers/upselling.ts +++ b/src/types/amadeus/namespaces/shopping/flight-offers/upselling.ts @@ -21,6 +21,7 @@ export interface CollectionMetaUpsell { }[]; } +// Types used in class export type FlightOffersUpsellingParams = { data: FlightOfferUpsellIn; }; diff --git a/tests/amadeus/namespaces.test.ts b/tests/amadeus/namespaces.test.ts index 3f46270..38cfb83 100644 --- a/tests/amadeus/namespaces.test.ts +++ b/tests/amadeus/namespaces.test.ts @@ -328,7 +328,7 @@ describe("Namespaces", () => { it(".amadeus.analytics.itineraryPriceMetrics.get", () => { amadeus["client"].get = vi.fn(); - amadeus.analytics.itineraryPriceMetrics.get(); + amadeus.analytics.itineraryPriceMetrics.get({} as any); expect(amadeus["client"].get).toHaveBeenCalledWith( "/v1/analytics/itinerary-price-metrics", {}