Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Fix npes
Browse files Browse the repository at this point in the history
  • Loading branch information
anduong96 committed Jan 24, 2024
1 parent d1c6cfd commit 5cfb302
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/services/flight/flights.payload.from.aero.data.box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ import { AeroDataBoxFlight } from '@app/vendors/aircraft/aero.data.box/types';
function toFlightPayload(
entry: AeroDataBoxFlight,
): RequiredKeys<Prisma.FlightUncheckedCreateInput, 'id'> {
const departureDate = moment.parseZone(
entry.departure.actualTimeLocal ?? entry.departure.scheduledTime.local,
);
const arrivalDate = moment.parseZone(
entry.arrival.actualTimeLocal ?? entry.arrival.scheduledTime.local,
);
const scheduledDeparture = entry.departure.scheduledTime?.local;
const scheduledArrival = entry.arrival.scheduledTime?.local;
const actualDeparture = entry.departure.actualTimeLocal;
const actualArrival = entry.arrival.actualTimeLocal;

if (!scheduledDeparture && !actualDeparture) {
throw new Error('Unable to find scheduled time for flight');
} else if (!actualArrival && !actualArrival) {
throw new Error('Unable to find arrival time for flight');
}

const departureDate = moment.parseZone(actualDeparture ?? scheduledDeparture);
const arrivalDate = moment.parseZone(actualArrival ?? scheduledArrival);

return {
aircraftTailNumber: entry.aircraft.reg,
Expand Down
2 changes: 1 addition & 1 deletion src/vendors/flights/flight.stats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class FlightStats {
const response = await request.json<Response>();

const flights = flatten(
response.data.map(entry => {
response?.data?.map(entry => {
const dateStr = `${entry.date1}-${entry.year}`;
const date = moment(dateStr, 'DD-MMM-YYYY');
return uniqBy(
Expand Down

0 comments on commit 5cfb302

Please sign in to comment.