Skip to content

Commit

Permalink
refactor(airportCourts): simplify lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
chohner committed Jan 25, 2024
1 parent 6450635 commit 520b478
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
16 changes: 3 additions & 13 deletions app/models/flows/fluggastrechte/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { guards as fluggastrechteVorabcheckGuards } from "~/models/flows/fluggastrechte/guards";
import fluggastrechteVorabcheckFlow from "~/models/flows/fluggastrechte/config.json";
import { fluggastrechteVorabcheckContext } from "~/models/flows/fluggastrechte/context";
import { findCourt } from "~/services/gerichtsfinder/amtsgerichtData.server";
import { type Jmtd14VTErwerberGerbeh } from "~/services/gerichtsfinder/types";

export const fluggastrechteVorabcheck = {
cmsSlug: "vorab-check-pages",
Expand All @@ -21,15 +19,7 @@ export const partnerCourtAirports = {
STR: "70629",
} as const;

function partnerCourtFromAirport(airport: string) {
if (airport in partnerCourtAirports) {
const zipCode =
partnerCourtAirports[airport as keyof typeof partnerCourtAirports];
return findCourt({ zipCode });
}
}
type PartnerAirport = keyof typeof partnerCourtAirports;

export const partnerCourtFromAirports = (airports: string[]) =>
airports
.map(partnerCourtFromAirport)
.filter((airport) => airport) as Jmtd14VTErwerberGerbeh[];
export const isPartnerAirport = (airport: string): airport is PartnerAirport =>
airport in partnerCourtAirports;
12 changes: 10 additions & 2 deletions app/routes/shared/result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ import {
isFeedbackForm,
} from "~/services/feedback/handleFeedback";
import CourtDetails from "~/components/CourtDetails";
import { partnerCourtFromAirports } from "~/models/flows/fluggastrechte";
import {
isPartnerAirport,
partnerCourtAirports,
} from "~/models/flows/fluggastrechte";
import Background from "~/components/Background";
import { findCourt } from "~/services/gerichtsfinder/amtsgerichtData.server";

export const loader = async ({
params,
Expand Down Expand Up @@ -106,7 +110,11 @@ export const loader = async ({
amtsgerichtCommon,
courts:
cmsData.pageType === "success" &&
partnerCourtFromAirports([data.startAirport, data.endAirport]),
[data.startAirport, data.endAirport]
.filter(isPartnerAirport)
.map((airport) =>
findCourt({ zipCode: partnerCourtAirports[airport] }),
),
},
{ headers: { "Set-Cookie": await commitSession(session) } },
);
Expand Down

0 comments on commit 520b478

Please sign in to comment.