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

fix: jsonb inserts, chapel-hill titles. #144

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/api/src/handlers/favorite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion packages/api/src/queries/favorite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RiderFavorite[]>`
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 (
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/types/favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface RiderFavoriteRow {
route_id: string
stop_id: string
favorite_id: number
ui: string
ui: Favorite
}
interface RiderFavoriteItem {
created: string
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/src/modules/location/api/predictions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down