Skip to content

Commit

Permalink
fix: undefined error on main map
Browse files Browse the repository at this point in the history
  • Loading branch information
ComeTiss committed Oct 16, 2024
1 parent fb11de9 commit 6a6b122
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions frontend/components/core/map/main-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default function CoreMap({ vesselsPositions }: CoreMapProps) {
)
}
function toSegmentsGeo({ segments, vesselId }: VesselExcursionSegments): any {
const segmentsGeo = segments.map((segment: VesselExcursionSegment) => {
const segmentsGeo = segments?.map((segment: VesselExcursionSegment) => {
return {
speed: segment.average_speed,
navigational_status: "unknown",
Expand All @@ -205,6 +205,6 @@ function toSegmentsGeo({ segments, vesselId }: VesselExcursionSegments): any {
}
}
})
return { vesselId, type: "FeatureCollection", features: segmentsGeo };
return { vesselId, type: "FeatureCollection", features: segmentsGeo ?? [] };
}

13 changes: 10 additions & 3 deletions frontend/services/backend-rest-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Vessel, VesselExcursion, VesselExcursionSegment, VesselPositions, VesselTrackingTimeDto } from "@/types/vessel";
import { ZoneVisitTimeDto } from "@/types/zone";
import axios, { InternalAxiosRequestConfig } from "axios";
import { log } from "console";

const BASE_URL = process.env.NEXT_PUBLIC_BACKEND_BASE_URL;
const API_KEY = process.env.NEXT_PUBLIC_BACKEND_API_KEY ?? 'no-key-found';
Expand Down Expand Up @@ -37,9 +38,15 @@ export function getVesselSegments(vesselId: number, excursionId: number) {
}

export async function getVesselFirstExcursionSegments(vesselId: number) {
const response = await getVesselExcursion(vesselId);
const excursionId = response?.data[0]?.id;
return !!excursionId ? getVesselSegments(vesselId, excursionId) : [];
try {
const response = await getVesselExcursion(vesselId);
const excursionId = response?.data[0]?.id;
return !!excursionId ? getVesselSegments(vesselId, excursionId) : [];

} catch(error) {
console.error(error);
return [];
}
}

export function getTopVesselsInActivity(startAt: string, endAt: string, topVesselsLimit: number) {
Expand Down

0 comments on commit 6a6b122

Please sign in to comment.