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: import from AirTrail JSON files #132

Merged
merged 1 commit into from
Nov 12, 2024
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
23 changes: 20 additions & 3 deletions src/lib/import/airtrail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ const AirTrailFile = z.object({
flights: z
.object({
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
departure: z.string().datetime('Invalid datetime').nullable(),
arrival: z.string().datetime('Invalid datetime').nullable(),
departure: z
.string()
.datetime({ offset: true, message: 'Invalid datetime' })
.nullable(),
arrival: z
.string()
.datetime({ offset: true, message: 'Invalid datetime' })
.nullable(),
duration: z.number().int().positive().nullable(),
})
.merge(flightAirportsSchema)
Expand Down Expand Up @@ -80,7 +86,18 @@ export const processAirTrailFile = async (input: string) => {
const user = dataUser
? users.find((user) => user.username === dataUser?.username)
: null;
const guestName = user ? null : seat.guestName;
/*
1. If the user is known, no guest name is needed.
2. If the user is unknown, but the guest name is known, use the guest name.
3. If the user is unknown and the guest name is unknown, use the provided display name (this could happen if the user is not in the database).
*/
const guestName = user
? null
: seat.guestName
? seat.guestName
: dataUser
? dataUser.displayName
: null;

return {
...seat,
Expand Down
Loading