-
Notifications
You must be signed in to change notification settings - Fork 9
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
Draft: interface separation discussion #2955
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,10 +60,24 @@ export interface GroupedSimpleDetours { | |
past: SimpleDetour[] | ||
} | ||
|
||
const MyNormalizedType = type({ | ||
my_id: detourId, | ||
my_route: string(), | ||
my_via_variant: string(), | ||
my_direction: string(), | ||
my_name: string(), | ||
my_intersection: string(), | ||
my_updated_at: number(), | ||
my_activated_at: coerce(date(), string(), (dateStr) => new Date(dateStr)), | ||
my_estimated_duration: string(), | ||
}) | ||
|
||
type MyNormalizedType = Infer<typeof MyNormalizedType> | ||
|
||
export const GroupedDetoursData = type({ | ||
active: array(ActivatedDetourData), | ||
draft: array(SimpleDetourData), | ||
past: array(SimpleDetourData), | ||
active: array(MyNormalizedType), | ||
draft: array(MyNormalizedType), | ||
past: array(MyNormalizedType), | ||
}) | ||
|
||
export type GroupedDetoursData = Infer<typeof GroupedDetoursData> | ||
|
@@ -72,8 +86,50 @@ export const groupedDetoursFromData = ( | |
groupedDetours: GroupedDetoursData | ||
): GroupedSimpleDetours => ({ | ||
active: groupedDetours.active | ||
.map(fromNormalizedToActivatedData) | ||
.map(simpleDetourFromActivatedData) | ||
.sort((a, b) => b.activatedAt.getTime() - a.activatedAt.getTime()), | ||
draft: groupedDetours.draft.map((detour) => simpleDetourFromData(detour)), | ||
past: groupedDetours.past.map((detour) => simpleDetourFromData(detour)), | ||
draft: groupedDetours.draft.map(fromNormalizedToSimple).map((detour) => simpleDetourFromData(detour)), | ||
past: groupedDetours.past.map(fromNormalizedToSimple).map((detour) => simpleDetourFromData(detour)), | ||
}) | ||
|
||
const fromNormalizedToSimple = ({ | ||
my_id, | ||
my_route, | ||
my_via_variant, | ||
my_direction, | ||
my_name, | ||
my_intersection, | ||
my_updated_at, | ||
}: MyNormalizedType): SimpleDetourData => ({ | ||
id: my_id, | ||
route: my_route, | ||
via_variant: my_via_variant, | ||
direction: my_direction, | ||
name: my_name, | ||
intersection: my_intersection, | ||
updated_at: my_updated_at | ||
}) | ||
|
||
const fromNormalizedToActivatedData = ({ | ||
my_id, | ||
my_route, | ||
my_via_variant, | ||
my_direction, | ||
my_name, | ||
my_intersection, | ||
my_updated_at, | ||
my_activated_at, | ||
my_estimated_duration }: MyNormalizedType): ActivatedDetourData => ({ | ||
activated_at: my_activated_at, | ||
estimated_duration: my_estimated_duration, | ||
details: { | ||
id: my_id, | ||
route: my_route, | ||
via_variant: my_via_variant, | ||
direction: my_direction, | ||
name: my_name, | ||
intersection: my_intersection, | ||
updated_at: my_updated_at | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'd need a third There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's a couple other spots I missed, but just wanted to give an example for isolating the frontend from backend db changes for at least one of the end points |
||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if we're dealing with a draft detour (never activated), this and estimated_duration would be null? (I could see past detours retaining their activated_at and estimated_duration because there's no reason to delete them, as long as status is also included somewhere in this normalized type)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this model also include the state blob, since some endpoints also return that to the frontend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't spend the time to figure out every field that we'd want to pass through, just grabbed the ones that are explicitly grabbed in the serde module. We'd need to go through and figure out what fields are needed top level and decide how we want to model the 'shape' portion of the detour, whether that lives in its own table or blob field