Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement(apiv2): use the OTP-UI conversion utility for legacy format #991

Merged
merged 5 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 2 additions & 42 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { zoomToPlace } from './map'

const { generateCombinations, generateOtp2Query } = coreUtils.queryGen
const { getTripOptionsFromQuery, getUrlParams } = coreUtils.query
const { convertGraphQLResponseToLegacy } = coreUtils.itinerary
const { randId } = coreUtils.storage

const LIGHT_GRAY = '666666'
Expand Down Expand Up @@ -782,47 +783,6 @@ const pickupDropoffTypeToOtp1 = (otp2Type) => {
}
}

/**
* Converts a leg from GraphQL format to legacy REST format.
* @param leg OTP2 GraphQL style leg
* @returns REST shaped leg
*/
const processLeg = (leg) => ({
...leg,
agencyBrandingUrl: leg.agency?.url,
agencyName: leg.agency?.name,
agencyUrl: leg.agency?.url,
alerts: aggregateAlerts(
leg.agency?.alerts,
leg.route?.alerts,
leg.to?.stop?.alerts,
leg.from?.stop?.alerts
),
alightRule: pickupDropoffTypeToOtp1(leg.dropoffType),
boardRule: pickupDropoffTypeToOtp1(leg.pickupType),
dropOffBookingInfo: {
latestBookingTime: leg.dropOffBookingInfo
},
from: {
...leg.from,
stopCode: leg.from.stop?.code,
stopId: leg.from.stop?.gtfsId
},
route: leg.route?.shortName,
routeColor: leg.route?.color,
routeId: leg.route?.id,
routeLongName: leg.route?.longName,
routeShortName: leg.route?.shortName,
routeTextColor: leg.route?.textColor,
to: {
...leg.to,
stopCode: leg.to.stop?.code,
stopId: leg.to.stop?.gtfsId
},
tripHeadsign: leg.trip?.tripHeadsign,
tripId: leg.trip?.gtfsId
})

const queryParamConfig = { modeButtons: DelimitedArrayParam }

export function routingQuery(searchId = null, updateSearchInReducer) {
Expand Down Expand Up @@ -962,7 +922,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
const withCollapsedShortNames =
response.data?.plan?.itineraries?.map((itin) => ({
...itin,
legs: itin.legs?.map(processLeg)
legs: itin.legs?.map(convertGraphQLResponseToLegacy)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Could you also update the dependencies to use core-utils 11.0.2 when it gets published?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, makes sense to roll that into this

}))

/* It is possible for a NO_TRANSIT_CONNECTION error to be
Expand Down