Files
nodeMap/services/webservice/fetchGisStationsStaticDistrictService.js
ISA ec31b36b3d feat: Healthcheck um Webservices, API-Routen und .env-Prüfungen erweitert
- Externe Webservices von TALAS V5 integriert und geprüft (Statuscode + Antwortstruktur)
- Eigene API-Endpunkte wie /api/talas_v5_DB/getDevices hinzugefügt und validiert
- Prüfung von NEXT_PUBLIC_USE_MOCKS zur Vermeidung von Mockdaten in Produktion
- Validierung der Umgebungsvariablen wie DB_HOST, DB_NAME und NODE_ENV ergänzt
- Response-Status 200 bei vollständigem Erfolg, 207 bei Teilfehlern
- Verbesserung der JSON-Antwortstruktur zur einfacheren Analyse
2025-06-05 15:23:59 +02:00

57 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Holt statische GIS-Stationen-Daten für Bezirke.
* Wechselt automatisch zwischen echten Daten und Mock-Daten via .env.local
*
* @returns {Promise<Array>} Liste mit Points[]
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
*/
export const fetchGisStationsStaticDistrictService = async () => {
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
if (useMocks) {
const mockBasePath = "/api/mocks/webservice/gisStationsStaticDistrict";
const mockURL = `${window.location.origin}${mockBasePath}`;
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
console.log("🧪 Mock-Modus aktiviert: fetchGisStationsStaticDistrictService ", mockURL);
}
const res = await fetch("/api/mocks/webservice/gisStationsStaticDistrict");
if (!res.ok) {
throw new Error("Mockdaten konnten nicht geladen werden");
}
const mockData = await res.json();
if (!Array.isArray(mockData.Points)) {
throw new Error("Mockdaten enthalten kein gültiges 'Points'-Feld");
}
return mockData.Points;
} else {
const baseUrl = `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx`;
const params = new URLSearchParams(window.location.search);
const idMap = params.get("m");
const idUser = params.get("u");
const url = `${baseUrl}/GisStationsStaticDistrict?idMap=${idMap}&idUser=${idUser}`;
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
console.log("📡 fetchGisStationsStaticDistrictService URL:", url);
}
const response = await fetch(url);
if (!response.ok) {
const message = `❌ Fehler: ${response.status} ${response.statusText}`;
console.error(message);
throw new Error(message);
}
const jsonResponse = await response.json();
if (!Array.isArray(jsonResponse.Points)) {
throw new Error("Antwortstruktur ungültig 'Points' fehlt");
}
return jsonResponse.Points;
}
};