diff --git a/packages/api/src/handlers/favorite.ts b/packages/api/src/handlers/favorite.ts index f7e07f5..ebac693 100644 --- a/packages/api/src/handlers/favorite.ts +++ b/packages/api/src/handlers/favorite.ts @@ -88,7 +88,7 @@ const favorite = { created: fav.created, rank: fav.rank, favoriteId: fav.favorite_id, - favorite: JSON.parse(fav.ui) + favorite: fav.ui })) ) } catch (err) { diff --git a/packages/api/src/queries/favorite.ts b/packages/api/src/queries/favorite.ts index 53cad45..9a33484 100644 --- a/packages/api/src/queries/favorite.ts +++ b/packages/api/src/queries/favorite.ts @@ -5,14 +5,23 @@ import type { RiderFavorite, RiderFavoriteRow } from '@busmap/common/types/favorites' +import type { SerializableParameter } from 'postgres' const addRiderFavorite = async (favorite: Favorite, userId: number) => { const { agency, route, stop } = favorite + /** + * Regarding the type annotation, + * either I'm missing something, or the type + * definitions for the postgres package are wrong: + * @see https://github.com/porsager/postgres/issues/625 + */ const riderFavoriteRow = await sql` WITH data (agency_id, route_id, stop_id, ui) AS ( - VALUES (${agency.id}, ${route.id}, ${stop.id}, ${JSON.stringify(favorite)}::jsonb) + VALUES (${agency.id}, ${route.id}, ${stop.id}, ${ + favorite as unknown as SerializableParameter + }::jsonb) ), inserted AS ( diff --git a/packages/common/src/types/favorites.ts b/packages/common/src/types/favorites.ts index 66cd028..b6d1349 100644 --- a/packages/common/src/types/favorites.ts +++ b/packages/common/src/types/favorites.ts @@ -26,7 +26,7 @@ interface RiderFavoriteRow { route_id: string stop_id: string favorite_id: number - ui: string + ui: Favorite } interface RiderFavoriteItem { created: string diff --git a/packages/ui/src/modules/location/api/predictions.ts b/packages/ui/src/modules/location/api/predictions.ts index 3f2e4fb..ba73141 100644 --- a/packages/ui/src/modules/location/api/predictions.ts +++ b/packages/ui/src/modules/location/api/predictions.ts @@ -15,8 +15,15 @@ const get = async (point?: Point) => { const predictions: Prediction[] = [] preds.forEach(pred => { + /** + * Reconcile differences across the locations API and the route + * configuration data. Specifically, those relevant to allow the + * favorites tab to aggregate user selections made across the + * Nearby and Selector tabs correctly. + */ pred.agency.id = pred.agency.id.replace(/sfmta-cis/, 'sfmuni-sandbox') pred.agency.title = pred.agency.title.replace('SF Muni', 'San Francisco Muni') + pred.agency.title = pred.agency.title.replace('Chapel Hill', 'Chapel Hill Transit') /** * Not able to support SF Bay Ferry agency.