@entur/create-offer-configurations-from-offer-to-buy
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -1,5 +0,19 @@ | ||
import { SetRequired } from 'type-fest'; | ||
import { OfferToBuy } from './types/offersTypes'; | ||
import { OptionalProduct } from './types/offers2Types'; | ||
import { FareProductConfiguration, OfferToBuy } from './types/offersTypes'; | ||
import { OfferConfiguration } from './types/reserveOfferTypes'; | ||
declare type OfferConfigurationWithCountOne = SetRequired<OfferConfiguration, 'selectedTravellerIds'> & { | ||
export declare type SetRequired<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>; | ||
/** | ||
* This is a stripped down version of the Offer types, | ||
* containing only the root keys that we need. | ||
* The hope is that this will lead to fewer updates because | ||
* the type has changed. | ||
*/ | ||
declare type StrippedOptionalProduct = Pick<OptionalProduct, 'id' | 'selectableId'>; | ||
declare type StrippedFareProductConfiguration = Pick<FareProductConfiguration, 'id' | 'selectableId'>; | ||
declare type StrippedOffer = { | ||
salesPackageConfig: { | ||
fareProducts: StrippedFareProductConfiguration[]; | ||
}; | ||
}; | ||
declare type OfferConfigurationWithCountOne = SetRequired<OfferConfiguration, 'selectedTravellerIds' | 'selectableProductIds'> & { | ||
count?: 1; | ||
@@ -16,3 +30,4 @@ }; | ||
*/ | ||
export declare function createOfferConfigurationsFromOfferToBuy(offerToBuy: OfferToBuy): OfferConfigurationWithCountOne[]; | ||
export declare function createOfferConfigurationsFromOfferToBuy(offerToBuy: OfferToBuy, offerOrOptionalProducts: StrippedOffer | StrippedOptionalProduct[]): OfferConfigurationWithCountOne[]; | ||
export declare function getSelectableProductIdsMatchingNetexIdFromProducts(products: StrippedFareProductConfiguration[] | StrippedOptionalProduct[], netexId: string): string[]; | ||
export {}; |
@@ -10,7 +10,23 @@ /** | ||
*/ | ||
export function createOfferConfigurationsFromOfferToBuy(offerToBuy) { | ||
return offerToBuy.possibleTravellerIds.map((travellerIds) => ({ | ||
export function createOfferConfigurationsFromOfferToBuy(offerToBuy, offerOrOptionalProducts) { | ||
const netexIds = offerToBuy.withUpgradeProducts; | ||
const offerConfigurationsWithOnlyNetexIdsAsSelectableProductIds = offerToBuy.possibleTravellerIds.map((travellerIds) => ({ | ||
offerId: offerToBuy.id, | ||
selectableProductIds: netexIds, | ||
selectedTravellerIds: travellerIds | ||
})); | ||
return offerConfigurationsWithOnlyNetexIdsAsSelectableProductIds.map((offerConfiguration) => ({ | ||
...offerConfiguration, | ||
selectableProductIds: offerConfiguration.selectableProductIds.flatMap((netexId) => getSelectableProductIdsMatchingNetexIdFromProducts(isOffer(offerOrOptionalProducts) | ||
? offerOrOptionalProducts.salesPackageConfig.fareProducts | ||
: offerOrOptionalProducts, netexId)) | ||
})); | ||
} | ||
export function getSelectableProductIdsMatchingNetexIdFromProducts(products, netexId) { | ||
return products | ||
.filter((product) => product.id === netexId) | ||
.map((product) => product.selectableId); | ||
} | ||
function isOffer(offerOrOptionalProducts) { | ||
return 'salesPackageConfig' in offerOrOptionalProducts; | ||
} |
@@ -68,3 +68,3 @@ /** | ||
orderLineId?: string; | ||
/** A list of ids for selected products */ | ||
/** A list of ids for selected products. Duplicates are only supported for SupplementProducts which does not modify seating assignments for the PreassignedFareProduct */ | ||
selectableProductIds?: string[]; | ||
@@ -71,0 +71,0 @@ /** This field is used to specify which travellers will be included in the use of this offer. This field cannot be used in combination with count. It is validated against the travellers identified in the travellerMappings property of the selected Offer, as well as the legal number of UserProfiles per compartment when reserving a group product. When reserving a group product, validation is performed against the valid number of UserProfiles per compartment. When reserving regular products, a number of order lines will be made, corresponding to the number of selectedTravellerIds. Each order line will have one of the selectedTravellerIds. */ |
{ | ||
"name": "@entur/create-offer-configurations-from-offer-to-buy", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Create an array of offer configurations exactly as prescribed by the possibleTravellerIds field in an OfferToBuy", | ||
@@ -15,3 +15,3 @@ "main": "dist/index.js", | ||
"build": "rm -rf dist && npx tsc", | ||
"update-types": "npx swagger-typescript-api --path https://api.staging.entur.io/sales/v1/offers/api-docs/swagger.json --output source/types -n offersTypes.ts --no-client && npx swagger-typescript-api --path https://api.staging.entur.io/api-docs/reserve-offer?group=public --output source/types -n reserveOfferTypes.ts --no-client", | ||
"update-types": "npx swagger-typescript-api --path https://api.staging.entur.io/sales/v1/offers/api-docs/swagger.json --output source/types -n offersTypes.ts --no-client && npx swagger-typescript-api --path https://api.staging.entur.io/offers/v2-beta/api-docs/swagger.json --output source/types -n offers2Types.ts --no-client && npx swagger-typescript-api --path https://api.staging.entur.io/api-docs/reserve-offer?group=public --output source/types -n reserveOfferTypes.ts --no-client", | ||
"test": "jest", | ||
@@ -44,3 +44,2 @@ "lint": "npx prettier --check *.{md,json} .*.js; xo", | ||
"prettier": "^2.3.2", | ||
"type-fest": "^0.21.3", | ||
"typescript": "^4.4.3", | ||
@@ -47,0 +46,0 @@ "xo": "^0.42.0" |
@@ -25,8 +25,11 @@ # @entur/create-offer-configurations-from-offer-to-buy | ||
createOfferConfigurationsFromOfferToBuy({ | ||
id: "7048884e-2c16-4305-92cc-b56fb4ea779a", | ||
numberToBuy: 2, | ||
withUpgradeProducts: [], | ||
possibleTravellerIds: [["3543283", "3518762"], ["ADULT-0-anonymous"]], | ||
}); | ||
createOfferConfigurationsFromOfferToBuy( | ||
{ | ||
id: "7048884e-2c16-4305-92cc-b56fb4ea779a", | ||
numberToBuy: 2, | ||
withUpgradeProducts: [], | ||
possibleTravellerIds: [["3543283", "3518762"], ["ADULT-0-anonymous"]], | ||
}, | ||
offerOrOptionalProducts | ||
); | ||
@@ -33,0 +36,0 @@ /* |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187111
21
11
4105
66