@opentripplanner/core-utils 9.0.0-alpha.35 → 9.0.0-alpha.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/itinerary.ts CHANGED
@@ -570,7 +570,7 @@ export function getLegCost(
570
570
  leg: Leg,
571
571
  mediumId: string,
572
572
  riderCategoryId: string
573
- ): { price: Money; transferAmount?: Money | undefined } {
573
+ ): { price?: Money; transferAmount?: Money | undefined } {
574
574
  if (!leg.fareProducts) return { price: undefined };
575
575
  const relevantFareProducts = leg.fareProducts.filter(({ product }) => {
576
576
  return (
@@ -602,17 +602,19 @@ export function getItineraryCost(
602
602
  legs: Leg[],
603
603
  mediumId: string,
604
604
  riderCategoryId: string
605
- ): Money {
606
- return legs
605
+ ): Money | undefined {
606
+ const legCosts = legs
607
607
  .filter(leg => leg.fareProducts?.length > 0)
608
608
  .map(leg => getLegCost(leg, mediumId, riderCategoryId).price)
609
- .reduce<Money>(
610
- (prev, cur) => ({
611
- amount: prev.amount + cur?.amount || 0,
612
- currency: prev.currency ?? cur?.currency
613
- }),
614
- { amount: 0, currency: null }
615
- );
609
+ .filter(cost => cost !== undefined);
610
+ if (legCosts.length === 0) return undefined;
611
+ return legCosts.reduce<Money>(
612
+ (prev, cur) => ({
613
+ amount: prev.amount + cur?.amount || 0,
614
+ currency: prev.currency ?? cur?.currency
615
+ }),
616
+ { amount: 0, currency: null }
617
+ );
616
618
  }
617
619
 
618
620
  const pickupDropoffTypeToOtp1 = otp2Type => {