From baf6e471378db2df2c6065e30dbaa151c70f1a9e Mon Sep 17 00:00:00 2001 From: Johan Ohly Date: Tue, 12 Nov 2024 18:45:48 +0100 Subject: [PATCH] fix: expect timestamp offset when importing AirTrail JSON --- src/lib/import/airtrail.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/lib/import/airtrail.ts b/src/lib/import/airtrail.ts index 68f9964..5f329d8 100644 --- a/src/lib/import/airtrail.ts +++ b/src/lib/import/airtrail.ts @@ -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) @@ -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,