diff --git a/.env.local b/.env.local index 5ba05de6b..0a72b7e14 100644 --- a/.env.local +++ b/.env.local @@ -13,7 +13,7 @@ NEXT_PUBLIC_DEBUG_LOG=true #auf dem Entwicklungsrechner dev läuft auf Port 3000 und auf dem Server prod auf Port 80, aber der WebService ist immer auf PORT 80 NEXT_PUBLIC_API_PORT_MODE=dev -NEXT_PUBLIC_USE_MOCKS=false +NEXT_PUBLIC_USE_MOCKS=true # Der Unterordner talas5 gleich hinter der IP-Adresse (oder Servername) muss konfigurierbar sein. # Es muss auch möglich sein kein Unterorder anzugeben (z.B. nur http://talasserver/). diff --git a/__mocks__/webservice/gisLinesStatus.js b/__mocks__/webservice/gisLinesStatus.js index 3f2e6adde..a80f6eb26 100644 --- a/__mocks__/webservice/gisLinesStatus.js +++ b/__mocks__/webservice/gisLinesStatus.js @@ -130,7 +130,7 @@ export const mockGisLinesStatus = { Modul: 2, DpName: "KUE02_Schleifenwert", ModulName: "L3", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -406,7 +406,7 @@ export const mockGisLinesStatus = { Modul: 1, DpName: "KUE01_Schleifenwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -418,7 +418,7 @@ export const mockGisLinesStatus = { Modul: 2, DpName: "KUE02_Schleifenwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -430,7 +430,7 @@ export const mockGisLinesStatus = { Modul: 3, DpName: "KUE03_Schleifenwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -442,7 +442,7 @@ export const mockGisLinesStatus = { Modul: 4, DpName: "KUE04_Schleifenwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -466,7 +466,7 @@ export const mockGisLinesStatus = { Modul: 6, DpName: "KUE06_Schleifenwert", ModulName: "?", - ModulTyp: "KÜSS V2", + ModulTyp: "KÜSS V2", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -694,7 +694,7 @@ export const mockGisLinesStatus = { Modul: 2, DpName: "KUE02_Messwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -706,7 +706,7 @@ export const mockGisLinesStatus = { Modul: 3, DpName: "KUE03_Messwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -718,7 +718,7 @@ export const mockGisLinesStatus = { Modul: 4, DpName: "KUE04_Messwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -754,7 +754,7 @@ export const mockGisLinesStatus = { Modul: 1, DpName: "KUE01_Schleifenwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -766,7 +766,7 @@ export const mockGisLinesStatus = { Modul: 2, DpName: "KUE02_Schleifenwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -778,7 +778,7 @@ export const mockGisLinesStatus = { Modul: 3, DpName: "KUE03_Schleifenwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -790,7 +790,7 @@ export const mockGisLinesStatus = { Modul: 4, DpName: "KUE04_Schleifenwert", ModulName: "?", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -970,7 +970,7 @@ export const mockGisLinesStatus = { Modul: 3, DpName: "KUE03_Messwert", ModulName: "K4", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -1006,7 +1006,7 @@ export const mockGisLinesStatus = { Modul: 7, DpName: "KUE07_Messwert", ModulName: "?", - ModulTyp: "KÜSS V2", + ModulTyp: "KÜSS V2", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -1114,7 +1114,7 @@ export const mockGisLinesStatus = { Modul: 3, DpName: "KUE03_Schleifenwert", ModulName: "K4", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -1162,7 +1162,7 @@ export const mockGisLinesStatus = { Modul: 7, DpName: "KUE07_Schleifenwert", ModulName: "?", - ModulTyp: "KÜSS V2", + ModulTyp: "KÜSS V2", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -1210,7 +1210,7 @@ export const mockGisLinesStatus = { Modul: 6, DpName: "KUE06_Messwert", ModulName: "Kue 6", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -1222,7 +1222,7 @@ export const mockGisLinesStatus = { Modul: 7, DpName: "KUE07_Messwert", ModulName: "KUESS 7", - ModulTyp: "KÜSS V2", + ModulTyp: "KÜSS V2", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -1318,7 +1318,7 @@ export const mockGisLinesStatus = { Modul: 6, DpName: "KUE06_Schleifenwert", ModulName: "Kue 6", - ModulTyp: "Kü605µC", + ModulTyp: "Kü605µC", Message: "?", Level: -1, PrioColor: "#ffffff", @@ -1330,7 +1330,7 @@ export const mockGisLinesStatus = { Modul: 7, DpName: "KUE07_Schleifenwert", ModulName: "KUESS 7", - ModulTyp: "KÜSS V2", + ModulTyp: "KÜSS V2", Message: "?", Level: -1, PrioColor: "#ffffff", diff --git a/__mocks__/webservice/userRights.js b/__mocks__/webservice/userRights.js new file mode 100644 index 000000000..43a1ec29c --- /dev/null +++ b/__mocks__/webservice/userRights.js @@ -0,0 +1,293 @@ +// __mocks__/webservice/userRights.js +/** + * Mock-Daten für Benutzerrechte und Systemsichtbarkeit. + */ +export const mockUserRights = { + Name: "Liste aller angezeigten Systeme", + Zeitstempel: "2025-05-29T08:57:47.6981898+02:00", + IdMap: "12", + Systems: [ + { + IdSystem: 1, + Name: "TALAS", + Longname: "Talas Meldestationen", + Allow: 1, + Icon: 1, + }, + { + IdSystem: 2, + Name: "ECI", + Longname: "ECI Geräte", + Allow: 1, + Icon: 2, + }, + { + IdSystem: 3, + Name: "ULAF", + Longname: "ULAF Geräte", + Allow: 0, + Icon: 3, + }, + { + IdSystem: 5, + Name: "GSM Modem", + Longname: "LR77 GSM Modems", + Allow: 1, + Icon: 5, + }, + { + IdSystem: 6, + Name: "Cisco Router", + Longname: "Cisco Router", + Allow: 1, + Icon: 6, + }, + { + IdSystem: 7, + Name: "WAGO", + Longname: "WAGO I/O Systeme", + Allow: 1, + Icon: 7, + }, + { + IdSystem: 8, + Name: "Siemens", + Longname: "Siemens Notrufsysteme", + Allow: 1, + Icon: 8, + }, + { + IdSystem: 9, + Name: "OTDR", + Longname: "Glasfaserüberwachung OTU", + Allow: 1, + Icon: 9, + }, + { + IdSystem: 10, + Name: "WDM", + Longname: " Wavelength Division Multiplexing", + Allow: 1, + Icon: 10, + }, + { + IdSystem: 11, + Name: "GMA", + Longname: "Glättemeldeanlagen", + Allow: 1, + Icon: 11, + }, + { + IdSystem: 13, + Name: "Messstellen", + Longname: "Messstellen", + Allow: 0, + Icon: 13, + }, + { + IdSystem: 30, + Name: "TK-Komponenten", + Longname: "TK-Komponenten", + Allow: 1, + Icon: 30, + }, + { + IdSystem: 100, + Name: "TALAS ICL", + Longname: "Talas ICL Unterstationen", + Allow: 1, + Icon: 100, + }, + { + IdSystem: 110, + Name: "DAUZ", + Longname: "Dauerzählstellen", + Allow: 1, + Icon: 110, + }, + { + IdSystem: 111, + Name: "SMS Modem", + Longname: "SMS Modem", + Allow: 1, + Icon: 111, + }, + { + IdSystem: 200, + Name: "Sonstige", + Longname: "Sonstige", + Allow: 1, + Icon: 200, + }, + ], + Rights: [ + { + IdRight: 1, + }, + { + IdRight: 2, + }, + { + IdRight: 3, + }, + { + IdRight: 5, + }, + { + IdRight: 6, + }, + { + IdRight: 7, + }, + { + IdRight: 8, + }, + { + IdRight: 10, + }, + { + IdRight: 11, + }, + { + IdRight: 12, + }, + { + IdRight: 20, + }, + { + IdRight: 22, + }, + { + IdRight: 23, + }, + { + IdRight: 25, + }, + { + IdRight: 30, + }, + { + IdRight: 40, + }, + { + IdRight: 41, + }, + { + IdRight: 42, + }, + { + IdRight: 43, + }, + { + IdRight: 44, + }, + { + IdRight: 45, + }, + { + IdRight: 46, + }, + { + IdRight: 47, + }, + { + IdRight: 48, + }, + { + IdRight: 49, + }, + { + IdRight: 50, + }, + { + IdRight: 51, + }, + { + IdRight: 52, + }, + { + IdRight: 55, + }, + { + IdRight: 56, + }, + { + IdRight: 60, + }, + { + IdRight: 61, + }, + { + IdRight: 62, + }, + { + IdRight: 63, + }, + { + IdRight: 64, + }, + { + IdRight: 65, + }, + { + IdRight: 68, + }, + { + IdRight: 69, + }, + { + IdRight: 70, + }, + { + IdRight: 71, + }, + { + IdRight: 72, + }, + { + IdRight: 73, + }, + { + IdRight: 79, + }, + { + IdRight: 80, + }, + { + IdRight: 90, + }, + { + IdRight: 93, + }, + { + IdRight: 94, + }, + { + IdRight: 95, + }, + { + IdRight: 96, + }, + ], +}; + +// 🔧 Laufzeit-Hilfsfunktionen für z. B. Mock-basierte UI-Tests + +/** + * Systemdaten zur Laufzeit ändern + * @param {number} id + * @param {object} changes + */ +export const updateSystem = (id, changes) => { + const system = mockUserRights.Systems.find((s) => s.IdSystem === id); + if (system) Object.assign(system, changes); +}; + +/** + * Ein System aus dem Mock entfernen + * @param {number} id + */ +export const deleteSystem = (id) => { + const index = mockUserRights.Systems.findIndex((s) => s.IdSystem === id); + if (index !== -1) mockUserRights.Systems.splice(index, 1); +}; diff --git a/config/appVersion.js b/config/appVersion.js index 273d94404..91991be9e 100644 --- a/config/appVersion.js +++ b/config/appVersion.js @@ -1,2 +1,2 @@ // /config/appVersion -export const APP_VERSION = "1.1.206"; +export const APP_VERSION = "1.1.207"; diff --git a/services/webservice/fetchGisStationsMeasurementsService.js b/services/webservice/fetchGisStationsMeasurementsService.js index 5418a33f5..9cb6d293a 100644 --- a/services/webservice/fetchGisStationsMeasurementsService.js +++ b/services/webservice/fetchGisStationsMeasurementsService.js @@ -1,31 +1,45 @@ // /services/webservice/fetchGisStationsMeasurementsService.js export const fetchGisStationsMeasurementsService = 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 || ""; - const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`; + if (useMocks) { + console.log("🧪 Mock-Modus aktiviert: fetchGisStationsMeasurementsService"); + const { mockGisStationsMeasurements } = await import("../../__mocks__/webservice/gisStationsMeasurements.js"); + return mockGisStationsMeasurements.Statis; + } else { + const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`; - const params = new URLSearchParams(window.location.search); - const idMap = params.get("m"); - const idUser = params.get("u"); + const params = new URLSearchParams(window.location.search); + const idMap = params.get("m"); + const idUser = params.get("u"); - const url = `${baseUrl}/GisStationsMeasurements?idMap=${idMap}&idUser=${idUser}`; - console.log("📡 fetchGisStationsMeasurementsService URL:", url); + const url = `${baseUrl}/GisStationsMeasurements?idMap=${idMap}&idUser=${idUser}`; + console.log("📡 fetchGisStationsMeasurementsService URL:", url); - const response = await fetch(url); + const response = await fetch(url); + if (!response.ok) { + const message = `❌ Fehler: ${response.status} ${response.statusText}`; + console.error(message); + throw new Error(message); + } - if (!response.ok) { - const message = `❌ Fehler: ${response.status} ${response.statusText}`; - console.error(message); - throw new Error(message); + const text = await response.text(); + + let jsonResponse; + try { + jsonResponse = JSON.parse(text); + } catch (e) { + console.error("❌ Fehler beim JSON-Parsing der Antwort:", text); + throw new Error("Antwort ist kein gültiges JSON"); + } + + if (!jsonResponse?.Statis) { + throw new Error("Antwortstruktur ungültig – 'Statis' fehlt"); + } + + return jsonResponse.Statis; } - - const jsonResponse = await response.json(); - - if (!jsonResponse?.Statis) { - throw new Error("Antwortstruktur ungültig – 'Statis' fehlt"); - } - - return jsonResponse.Statis; }; diff --git a/services/webservice/fetchGisStationsStaticDistrictService.js b/services/webservice/fetchGisStationsStaticDistrictService.js index 54dc3f661..7ec3ecdf8 100644 --- a/services/webservice/fetchGisStationsStaticDistrictService.js +++ b/services/webservice/fetchGisStationsStaticDistrictService.js @@ -2,35 +2,42 @@ /** * Holt statische GIS-Stationen-Daten für Bezirke. + * Wechselt automatisch zwischen echten Daten und Mock-Daten via .env.local * * @returns {Promise} 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 mode = process.env.NEXT_PUBLIC_API_PORT_MODE; const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ""; - const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`; - const params = new URLSearchParams(window.location.search); - const idMap = params.get("m"); - const idUser = params.get("u"); + if (useMocks) { + console.log("🧪 Mock-Modus aktiviert: fetchGisStationsStaticDistrictService"); + const { mockGisStationsStaticDistrict } = await import("../../__mocks__/webservice/gisStationsStaticDistrict.js"); + return mockGisStationsStaticDistrict.Points; + } else { + const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`; - const url = `${baseUrl}/GisStationsStaticDistrict?idMap=${idMap}&idUser=${idUser}`; - console.log("📡 fetchGisStationsStaticDistrictService URL:", url); + const params = new URLSearchParams(window.location.search); + const idMap = params.get("m"); + const idUser = params.get("u"); - const response = await fetch(url); + const url = `${baseUrl}/GisStationsStaticDistrict?idMap=${idMap}&idUser=${idUser}`; + console.log("📡 fetchGisStationsStaticDistrictService URL:", url); - if (!response.ok) { - const message = `❌ Fehler: ${response.status} ${response.statusText}`; - console.error(message); - throw new Error(message); + 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 (!jsonResponse?.Points) { + throw new Error("Antwortstruktur ungültig – 'Points' fehlt"); + } + + return jsonResponse.Points; } - - const jsonResponse = await response.json(); - - if (!jsonResponse?.Points) { - throw new Error("Antwortstruktur ungültig – 'Points' fehlt"); - } - - return jsonResponse.Points; }; diff --git a/services/webservice/fetchGisStationsStatusDistrictService.js b/services/webservice/fetchGisStationsStatusDistrictService.js index 1ef5d4230..8421bb51a 100644 --- a/services/webservice/fetchGisStationsStatusDistrictService.js +++ b/services/webservice/fetchGisStationsStatusDistrictService.js @@ -2,36 +2,44 @@ /** * Holt Statusinformationen der GIS-Bezirksstationen. + * Unterstützt dynamische Umschaltung zwischen echten und Mock-Daten. * * @returns {Promise} Liste mit Statis[] * @throws {Error} bei Fehler oder ungültiger Antwortstruktur */ export const fetchGisStationsStatusDistrictService = 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 || ""; - const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`; + if (useMocks) { + console.log("🧪 Mock-Modus aktiviert: fetchGisStationsStatusDistrictService"); + const { mockGisStationsStatusDistrict } = await import("../../__mocks__/webservice/gisStationsStatusDistrict.js"); + return mockGisStationsStatusDistrict.Statis; + } else { + const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`; - const params = new URLSearchParams(window.location.search); - const idMap = params.get("m"); - const idUser = params.get("u"); + const params = new URLSearchParams(window.location.search); + const idMap = params.get("m"); + const idUser = params.get("u"); - const url = `${baseUrl}/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`; - console.log("📡 fetchGisStationsStatusDistrictService URL:", url); + const url = `${baseUrl}/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`; + console.log("📡 fetchGisStationsStatusDistrictService URL:", url); - const response = await fetch(url); + const response = await fetch(url); - if (!response.ok) { - const message = `❌ Fehler: ${response.status} ${response.statusText}`; - console.error(message); - throw new Error(message); + if (!response.ok) { + const message = `❌ Fehler: ${response.status} ${response.statusText}`; + console.error(message); + throw new Error(message); + } + + const jsonResponse = await response.json(); + + if (!jsonResponse?.Statis) { + throw new Error("Antwortstruktur ungültig – 'Statis' fehlt"); + } + + return jsonResponse.Statis; } - - const jsonResponse = await response.json(); - - if (!jsonResponse?.Statis) { - throw new Error("Antwortstruktur ungültig – 'Statis' fehlt"); - } - - return jsonResponse.Statis; }; diff --git a/services/webservice/fetchGisSystemStaticService.js b/services/webservice/fetchGisSystemStaticService.js index 0aa5258fc..215fe4f8c 100644 --- a/services/webservice/fetchGisSystemStaticService.js +++ b/services/webservice/fetchGisSystemStaticService.js @@ -1,37 +1,43 @@ // /services/webservice/fetchGisSystemStaticService.js /** - * Holt GIS-Systemdaten (Systemübersicht) vom TALAS WebService. + * Holt GIS-Systemdaten (Systemübersicht) vom TALAS WebService oder aus Mocks. * * @returns {Promise} 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 || ""; - const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`; + if (useMocks) { + console.log("🧪 Mock-Modus aktiviert: fetchGisSystemStaticService"); + const { mockGisSystemStatic } = await import("../../__mocks__/webservice/gisSystemStatic.js"); + return mockGisSystemStatic.Systems; + } else { + const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`; - const params = new URLSearchParams(window.location.search); - const idMap = params.get("m"); - const idUser = params.get("u"); + 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 url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`; + console.log("📡 fetchGisSystemStaticService von service URL:", url); - const response = await fetch(url); + const response = await fetch(url); + if (!response.ok) { + const message = `❌ Fehler: ${response.status} ${response.statusText}`; + console.error(message); + throw new Error(message); + } - 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; } - - const jsonResponse = await response.json(); - - if (!jsonResponse?.Systems) { - throw new Error("Antwortstruktur ungültig – 'Systems' fehlt"); - } - - return jsonResponse.Systems; }; diff --git a/services/webservice/fetchUserRightsService.js b/services/webservice/fetchUserRightsService.js index b2cb06e38..5ae85df7d 100644 --- a/services/webservice/fetchUserRightsService.js +++ b/services/webservice/fetchUserRightsService.js @@ -1,28 +1,44 @@ // /services/webservice/fetchUserRightsService.js + +/** + * Holt Benutzerrechte aus TALAS-Webservice oder aus Mocks. + * + * @returns {Promise} Rechte-Array + * @throws {Error} bei Lade- oder Strukturfehler + */ export const fetchUserRightsService = 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 || ""; - const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`; - const params = new URLSearchParams(window.location.search); - const idMap = params.get("m"); - const idUser = params.get("u"); + if (useMocks) { + console.log("🧪 Mock-Modus aktiviert: fetchUserRightsService"); + const { mockUserRights } = await import("../../__mocks__/webservice/userRights.js"); + return mockUserRights.Rights || []; + } else { + const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`; - const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`; - console.log("🔍 Rechte-Fetch URL:", url); + const params = new URLSearchParams(window.location.search); + const idMap = params.get("m"); + const idUser = params.get("u"); - const response = await fetch(url, { - method: "GET", - headers: { - Connection: "close", - }, - }); + const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`; + console.log("🔍 Rechte-Fetch URL:", url); - if (!response.ok) { - throw new Error("Fehler beim Abrufen der Benutzerrechte"); + const response = await fetch(url, { + method: "GET", + headers: { + Connection: "close", + }, + }); + + if (!response.ok) { + throw new Error("Fehler beim Abrufen der Benutzerrechte"); + } + + const json = await response.json(); + console.log("👤 Rechte-Response JSON:", json); + + return json.Rights || []; } - - const json = await response.json(); - console.log("👤 Rechte-Response JSON:", json); - return json.Rights || []; };