const baseUrl = `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx`;
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
// /services/webservice/fetchGisSystemStaticService.js
|
||
|
||
/**
|
||
* Holt GIS-Systemdaten (Systemübersicht) vom TALAS WebService oder aus Mocks.
|
||
*
|
||
* @returns {Promise<Array>} Liste mit Systems[]
|
||
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
|
||
*/
|
||
export const fetchGisSystemStaticService = async () => {
|
||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
|
||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||
|
||
if (useMocks) {
|
||
console.log("🧪 Mock-Modus aktiviert: fetchGisSystemStaticService");
|
||
const { mockGisSystemStatic } = await import("../../__mocks__/webservice/gisSystemStatic.js");
|
||
return mockGisSystemStatic.Systems;
|
||
} 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}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`;
|
||
console.log("📡 fetchGisSystemStaticService von service 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?.Systems)) {
|
||
throw new Error("Antwortstruktur ungültig – 'Systems' fehlt oder ist kein Array");
|
||
}
|
||
|
||
return jsonResponse.Systems;
|
||
}
|
||
};
|